Why does this:
give me this output:Code:#include <stdlib.h> #include <stdio.h> int main () { float this=20000.6; printf ("%.5f\n", this); }
20000.59961
Why does this:
give me this output:Code:#include <stdlib.h> #include <stdio.h> int main () { float this=20000.6; printf ("%.5f\n", this); }
20000.59961
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Because that's what it's supposed to do. See the manual. http://www.cplusplus.com/reference/c...io/printf.html
It's 5 digits after the decimal place, as per the manual. Not to mention floating points are approximations hence 20000.6 ~= 20000.59961
Last edited by zacs7; 07-14-2008 at 06:14 PM.
For more information about IEEE floats (which you're almost certainly using) look here.