Closed Bug 1752808 Opened 3 years ago Closed 2 years ago

Intl.NumberFormat "compact" doesn't return correctly formated number

Categories

(Core :: JavaScript: Internationalization API, defect, P2)

Firefox 97
ARM64
macOS
defect

Tracking

()

VERIFIED FIXED
101 Branch
Tracking Status
firefox-esr91 --- unaffected
firefox96 --- wontfix
firefox97 --- wontfix
firefox98 --- wontfix
firefox99 --- wontfix
firefox100 --- wontfix
firefox101 --- verified

People

(Reporter: niraj.pandey, Assigned: anba)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file)

Steps to reproduce:

I tried to use the NumberFormat object (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat) to format a currency into it's short notation. Here is the steps to reproduce it:

  1. Please visit this link (https://jsfiddle.net/w10jx25b/3/) both in Firefox and Chromium based browsers like Google Chrome.
  2. Check the console.log and you should some short notation currency values printed.
    I have included the code from the jsfiddle for reference:

let amount = -135773500;

const fmt = new Intl.NumberFormat('en-GB', {
style: 'currency',
currency: 'GBP',
minimumFractionDigits: 0,
maximumFractionDigits: 2,
notation: "compact",
compactDisplay: "short",
}).format(amount);

// Should be -£135.77M (Correct in Chromium browser)
// -£136M in firefox (incorrect)

console.log(fmt)

Actual results:

The printed output after running the code in Firefox is -£136 which seems to be the rounded value of the number provided. The printed value in Chromium based browser is £135.77M respecting the options set for minimum and maximum fraction digits.

Expected results:

Firefox should have outputted £135.77M similar to the Chromium based browser when minimum and maximum fraction digits were set or there needs to be some other way to prevent automatic rounding of the printed value.

OS: Unspecified → macOS
Hardware: Unspecified → ARM64

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript: Internationalization API' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Component: Untriaged → JavaScript: Internationalization API
Product: Firefox → Core

I get 135.77 in ESR, marking as a regression.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Mozregression
Last good revision: d49d84396d57671c34657fa3bac0e385d6d07f70
First bad revision: 7f44a968af7fd604fc13de9a398dec4ce8ebebd2
Pushlog:
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=d49d84396d57671c34657fa3bac0e385d6d07f70&tochange=7f44a968af7fd604fc13de9a398dec4ce8ebebd2

Regressed by: 1648137

It needs investigation, :dminor or :nordzilla would you mind doing some initial investigation as you all reviewed :anba's patches.

I can confirm that Chrome Canary has the original behavior still, so it's not part of CLDR changes like the other recent ones.

Severity: -- → S3
Flags: needinfo?(enordin)
Flags: needinfo?(dminor)
Priority: -- → P2
Has Regression Range: --- → yes
QA Whiteboard: [qa-regression-triage]

The regressing bug implemented NumberFormat v3. I'm not super familiar with the spec so it will take me some time to investigate this and determine whether the new behaviour is correct according to the updated spec, which has definitely changed how rounding is handled.

Flags: needinfo?(enordin)

This is probably just the issue mentioned at https://github.com/tc39/ecma402/pull/575#pullrequestreview-730209467.

Updates SetNumberFormatDigitOptions to the latest draft spec to correctly
handle compact notation with fractional digits.

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Flags: needinfo?(dminor)
Pushed by andre.bargull@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/fa4f2b7a8c6e
Update SetNumberFormatDigitOptions to latest draft spec. r=platform-i18n-reviewers,dminor
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch

The patch landed in nightly and beta is affected.
:anba, is this bug important enough to require an uplift?
If not please set status_beta to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(andrebargull)
Flags: needinfo?(andrebargull)
Flags: qe-verify+

I have reproduced this issue using Firefox 98.0a1 (2022.01.31) on Win 10 x64.
I can confirm this issue is fixed, Firefox have outputted -£135.77M, I verified using Firefox 101.0b6 on macOS 11 ARM, Win 10 x64, macOS 10.15 and Ubuntu 20.04 x64.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: