When I perform the following code, it has a problem:
float number = 999999999;
printf("%lf", number);
The result is 10000000000
instead of 999999999
.
Why isn't it 999999999
?
When I perform the following code, it has a problem:
float number = 999999999;
printf("%lf", number);
The result is 10000000000
instead of 999999999
.
Why isn't it 999999999
?
Typical float
can represent exactly about 232 different numbers like 1234.0 and -0.125. 999999999
is not one of them. 10000000000.0f
is the closest float
alternative.
The approximation occurred during the assignment
float number = 999999999; // Really assigned 10000000000.0f