Possible Duplicate:
Precision of Floating Point
Can you compare floating point values exactly to zero?
floating point issue
In my c++ code I have the string: “0.55”.
And I want to convert it to float value “0.55”, but all function I used give me the float value “0.55000001”.
Why? How can I take the clear value?
Last version of code is:
wstring s = L"0.55";
float f = stof(s);
Floats are not exact. This is because there are infinite number of possible values, but only finite number of bits to represent them!
So because
0.55cannot be represented, it gives you the value0.55000001instead.More info can be found in: what every programmer should know about floating points arithmetics