I am unable to understand why C++ division behaves the way it does. I have a simple program which divides 1 by 10 (using VS 2003)
double dResult = 0.0;
dResult = 1.0/10.0;
I expect dResult to be 0.1, However i get 0.10000000000000001
- Why do i get this value, whats the problem with internal representation of double/float
- How can i get the correct value?
Thanks.
Because
allmost modern processors use binary floating-point, which cannot exactly represent 0.1 (there is no way to represent 0.1 asm * 2^ewith integermande).If you want to see the “correct value”, you can print it out with e.g.: