I have do some test about Number.prototype.toFixed
method in chrome(v60.0.3112.101) console and found sth puzzled me.
Why 1.15.toFixed(1)
return "1.1" but not the "1.2"?
Why 1.05.toFixed(1)
return "1.1" but not the "1.0"?
and so on...
I do research in the ECMAScript specification.
NOTE 1 toFixed returns a String containing this Number value represented in decimal fixed-point notation with fractionDigits digits after the decimal point. If fractionDigits is undefined, 0 is assumed.
I know what's the fixed point notation.But I can't explain the puzzles above. Could someone give a clear explaination?
BTW, I think the details arithmetic under the specification should be improved. Saying 1.105 for instance, the relative arithmetic is the following:
Let n be an integer for which the exact mathematical value of n ÷ 10^f - x is as close to zero as possible. If there are two such n, pick the larger n.
According to pick the larger n
, 111 should be taken into consideration but not the 110, which is contradicted to reality.