Re: fprintf: number of digits for exponent



Thomas wrote:
>
>
> Hello,
>
> I tried to print numbers in scientific notation with fprintf. The
> standard size for the exponent is 3 digits, ie
>
> a=0.004
> fprintf('%8.2E',a)
>>>4.00E-003
>
> Is there a possibility to reduce the number of digits for the
> exponent to 2? I need the number to be printed in the format
>
> 4.00E-03
>
> Thanks,
>
> Thomas

A solution:
fprintf(regexprep(sprintf('%8.2E',a),'E-0','E-'))

hth
Jos
.



Relevant Pages

  • Re: Exponent Format specifiers for %g
    ... provide a consitent output format with 3 digits of the exponent. ... It is not consistent with the ANSI standard for printf. ... fails to conform to C99, ...
    (microsoft.public.vc.language)
  • Re: Very small numbers & formatting
    ... full exponent can be shown. ... The case in standard is slightly more restrictive than this. ... If you explicitly specify the exponent width, ... more than 3 digits of exponent. ...
    (comp.lang.fortran)
  • fprintf: number of digits for exponent
    ... I tried to print numbers in scientific notation with fprintf. ... standard size for the exponent is 3 digits, ... Is there a possibility to reduce the number of digits for the ...
    (comp.soft-sys.matlab)
  • Re: Exponent Format specifiers for %g
    ... %g behaves like %e. ... The standard ... has this to say about %e: "The exponent always contains at least two ... digits, and only as many more digits as necessary to represent the ...
    (microsoft.public.vc.language)
  • Re: BigNum -- Floating Point
    ... The 'N' is the number of decimal digits. ... The internal representation is really just a string of bits. ... the number of shifts for various multiples of ten: ... The 'exponent' is very closely related to ...
    (comp.programming)