|
|
back to boardCommon Boarda strange float point error in the 1070 local time, I find some error when converting double to int, int main() { double f=0.12; int t; t=int(f)*60+(f-int(f))*100; cout<<t<<endl; return 0; } I expect to get 12, but the result is 11, many compilers were tested, can anyone tell me how to avoid this? Re: a strange float point error I am afraid you van do nothing except smth like round (0.12*100) You see, because double values are really stored in binary format, numbers that can't be presented with a degree 2 denominator (2,8,128,etc) are presented by approximation. I think 0.12 is really something like 0.1199999????. Anmd his is the reason |
|
|