Possible Duplicate:
Floating point error in representation?
I have problem with this code
int cent;
int dollar ;
float cnt2dlr;
//convert cnt to doloar ;
cnt2dlr=(cnt)/(100);
The problem is when cnt = 175, cnt2dlr = 0.17,444444 and not 0.17,5
Any help?
Floating point numbers are not exact representations. They are approximations, so you cannot guarantee much precision. Read What Every Computer Scientist Should Know About Floating-Point Arithmetic
To increase the precision of the numbers, consider using a 64-bit
doubleinstead of a 32-bitfloat.