This is the code
char number[]="0.58";
double value = atof(number);
When I execute it value is 0.57999999999999996
Do you know why?
Thanks in advance
This is a discussion on atof is not exact within the C Programming forums, part of the General Programming Boards category; This is the code char number[]="0.58"; double value = atof(number); When I execute it value is 0.57999999999999996 Do you know ...
This is the code
char number[]="0.58";
double value = atof(number);
When I execute it value is 0.57999999999999996
Do you know why?
Thanks in advance
Yes. In computers, Floating points are only approximations.
Floats don't really store numbers the way you would probably think they do. They use a form of binary scientific notation (since your processor thinks in binary, not base 10).
So for instance you may say "the road is 1.1*10^3 miles away" in scientific notation. Your computer may think in terms of "that river is 3.2*2^12 miles away."
Converting between the two radii isn't accurate.