I am a beginner at C, and I don't understand how Is floating point math broken? relates to my question, since this is just printing a float
and does not involve any math with float
s.
I ran this code and it outputs a number that is different from what I assigned to the variable value
. I understand that a float will output 6 decimal places typically, but the actual output from this is 12345.099609
instead of 12345.100000
. double
gives me the expected output.
#include <stdio.h>
int main()
{
float value;
value = 12345.1;
printf("Value = %f\n", value);
return 0;
}
Here is how the output looks:
If it matters, I'm using Dev-C++ 5.11 to compile and run this code.