c - Why sciencific notation for "(double)123456" with "%.4g" conversion is "1.235e+05" instead of 1.234e+05 -
for me, seems normal 1.234e+05 when using conversion, because when revert '"%f\n", 1.235e+05' 123500.000000 instead of wished "123400.000000".
actually question is: why skipped "4" digit ?!
following example reinforces wanted say:
#include <stdio.h> int main(int argc, char **argv) { char x[100]; sprintf(x, "%.4g", (double)123456); printf(">%s<\n", x); printf("%f\n", 1.235e+05); return 0; }
thanks, valentin
printf
limited precision not truncate; rounds per current rounding mode. default mode round-to-nearest. since 123456 closer 123500 123400, former value printed.
Comments
Post a Comment