Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.
Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.
It reminds me of the anecdote about the missing programmer. And he is sitting in a cold bath, shampoo in his hands with the instructions "soap, rinse, repeat".
Dmitry Fedoseev: It reminds me of a joke about a programmer who has gone missing. He was sitting in a cold bath, shampoo in his hands with the instruction "soap, rinse and repeat".
Why does a language need such precision: that the number (for example) "0.7" is actually stored as "0.69999..."?
Is this actually used somewhere? I'm used to counting numbers like in a calculator, it shows accurately.
Yes, perhaps the calculator itself rounds something, and doesn't store the exact numbers itself...
Who needs to use such approximate figures with infinite fractions instead of exact values?
Divide it, get 0.7 and don't bother with cropping or rounding :-)
Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So, according to the algorithm suggested above, normalize to three digits, we get 1.000, discard one and get 1.00, but not 0.99.
The devil is in the mix... 2.6, of course.
It's time for bed.
What's 5? Normalising such a number turns all 9's into zeros, so normalising and then discarding would give wrong results.
DoubleToString(0.99999,5)
Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.
Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.
Yeah... and suddenly we have the number 0.999999 instead of 0.999999.
It reminds me of a joke about a programmer who has gone missing. He was sitting in a cold bath, shampoo in his hands with the instruction "soap, rinse and repeat".
Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So, according to the algorithm suggested above, normalize to three digits, we get 1.000, discard one and get 1.00, but not 0.99.
try to get a result of0.99999999999999999
X = 0.99999999999999999
10*X = 10*0.99999999999999999
10*X-X = 10*0.999999999999999-0.9999999999999
9*X = 9*0.99999999999999999
we get 9*X = 9 or X equals 1 (one)
v1 = (1/3) = 0.33333333 | v2 = 3*(1/3) = 1.00000000
or 0.999999999999999 = 1.0
v1 (1.00000000) >= 1.0