New issue
Advanced search Search tips

Issue 850835 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jun 2018
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 3
Type: Bug



Sign in to add a comment

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


 

Comment 1 by woxxom@gmail.com, Jun 8 2018

JavaScript implements IEEE 754 double precision specification for floating numbers, which can reliably represent only 15 decimal digits, which leads to all kinds of indeterminate behavior when the 16th digit is involved. This behavior is common in programming languages.
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).
Components: Platform>Apps>Default>Hterm
Components: -Platform>Apps>Default>Hterm
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.
Status: WontFix (was: Unconfirmed)
As per #1. Exact same behavior in Firefox as well.

Sign in to add a comment