NumberFormat precision rounding issue - rounds incorrectly when very close to the floating point threshold
Reported by
aah...@atlassian.com,
Jun 8 2018
|
||||
Issue description
Chrome Version: 66.0.3359.139 (Official Build) (64-bit)
JavaScript V8 6.6.346.26
Steps To Reproduce:
Run this in the Console
```
> new Intl.NumberFormat('en', { maximumFractionDigits: 1 }).format(1023.949999999995)
"1,024"
> new Intl.NumberFormat('en', { maximumFractionDigits: 1 }).format(1023.949999999994)
"1,023.9"
```
Expected Result: Both of these should return "1,023.9" - they are both below 1023.95
Actual Result: The top one returns 1024 for some reason. We thought perhaps it was because of some math being done inside the formatter but the minimal math needed is still fine in a console:
```
> Math.floor(1023.949999999995 * 10)/10
1023.9
```
How frequently does this problem reproduce? (Always, sometimes, hard to
reproduce?) Always
What is the impact to the user, and is there a workaround? If so, what is
it? Tiny impact if I'm being honest
,
Jun 8 2018
Yeah I figured as much. Feel free to close. Thanks for the note. The weird thing for me was that I couldn't figure out how the problem was being hit (because manually doing the math worked in the console, as mentioned above).
,
Jun 8 2018
,
Jun 8 2018
not sure why hterm was tagged here. afaict, this is a bog standard IEEE 754 floating point question that is purely in the v8/JS runtime.
,
Jun 11 2018
As per #1. Exact same behavior in Firefox as well. |
||||
►
Sign in to add a comment |
||||
Comment 1 by woxxom@gmail.com
, Jun 8 2018