chakra-core / chakra-core/ChakraCore
Number.prototype.toFixed() sometimes rounds to non-closest value
Open
Bug
Severity: 2
- Dominant language
- JavaScript
- Stars
- 9.3k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using Microsoft Edge 42.17134.1.0.
Following code shows unexpected result with Microsoft Edge.
```
x1 = 0.015;
x2 = 0.045;
console.log(x1.toFixed(2)); // Edge: 0.02, Chrome: 0.01
console.log(x2.toFixed(2)); // Edge: 0.05, Chrome: 0.04
```
ECMAScript specification requires that `Number.prototype.toFixed()` must return mathematically closest decimal expression to `x1` and `x2`. The exact value of `x1` is 0.01499999999999999944... and `x2` is 0.0449999999999999983... , so the return value should be `"0.01"` and `"0.04"`;
Contributor guide
Assessment
This issue has not been assessed yet.