how to print E formated numbers.

3 views (last 30 days)
I have numbers such as 0.1032E-02 (say) If I read this as x = 0.1032E-02 and save it to a text file using fopen, and fprintf fid = fopen('Testing.txt','wt'); fprintf(fid, '%15.5E\n',x) it always prints x as 1.032E-03 but I would like the 0 in front just as the way I assigned the value to x. How do i do it?
Pappu Murthy
Pappu Murthy on 8 Mar 2018
Yes. I want the numbers printed as 0.0000E-nn format with leading zero. But fprintf does not let the leading zero.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 8 Mar 2018
Try this little utility anonymous function I wrote a while back to solve this exact problem:
a = 0.1032E-02
expstr = @(x) [x*10.^floor(-log10(abs(x))) floor(log10(abs(x))+1)];
Result = sprintf('%.7fE%+03d', expstr(a))
Result =
Star Strider
Star Strider on 8 Mar 2018
As always, my (our) pleasure!

Sign in to comment.

More Answers (0)


Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!