This is a very simple question
Is there a way to format float for a printf, So that xx is the important decimal to it?
So I say, % 5.3f float, but if I
float x = 0.00001899383 How do I output 0.000018 9? The first three non-zero points?
"% .3g" will try to output three important digits, either scientific or fixed format In.
at bjg:
Program
#include & lt; Stdio.h & gt; Int main () {Double A = 123456789e-15; Int i = 0; For (i = -10; i & lt; = 10; ++ i) {printf ("% .3g \ n", a); One * = 10; } Return 0; } Output
1.23e-07 1.23e-06 1.23e-05 0.000123 0.00123 0.0123 0.123 1.23 12.3 123 1.23 E + 03 1.23 E +04 1.23e + 05 1.23 E + 06 1.23 E + 07 1.23E + 08 1.23E + 09.23E + 10 1.23E + 11.23E + 12 1.23E + 13 / Html>
Comments
Post a Comment