%g format in printf

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Sep 7 14:24:34 AEST 1989


In article <19426 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
-In article <1439 at hiatus.dec.com> daniels at grue.dec.com (Bradford R. Daniels)
-writes:
->Also, the definition of significant digits I learned in my high
->school science classes says that if I am asked to print out 1024
->with 1 significant digit, I should get 1000 printed out.  Is that
->correct?
-No: `1000' has four significant digits (as does `1.000'); you need `1e3'.
-I have seen arguments on both sides of this, but only believe the one
-that says `the number of digits written is the number of significant
-digits'.

While 1.000 indeed unambiguously has 4 significant digits, the number
of significant digits in 1000 is not evident from inspection; it could
be from 1 to 4.  When you ask printf() to format 1024 with 1 significant
digit in a fairly wide field, it's supposed to produce 1000 not 1e3.



More information about the Comp.std.c mailing list