Intl.NumberFormat "compact" doesn't return correctly formated number
Categories
(Core :: JavaScript: Internationalization API, defect, P2)
Tracking
()
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:
- Please visit this link (https://jsfiddle.net/w10jx25b/3/) both in Firefox and Chromium based browsers like Google Chrome.
- 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.
Reporter | ||
Updated•3 years ago
|
Comment 1•3 years ago
|
||
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.
Comment 2•3 years ago
|
||
I get 135.77 in ESR, marking as a regression.
Comment 3•3 years ago
|
||
Mozregression
Last good revision: d49d84396d57671c34657fa3bac0e385d6d07f70
First bad revision: 7f44a968af7fd604fc13de9a398dec4ce8ebebd2
Pushlog:
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=d49d84396d57671c34657fa3bac0e385d6d07f70&tochange=7f44a968af7fd604fc13de9a398dec4ce8ebebd2
Comment 4•3 years ago
|
||
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.
Updated•3 years ago
|
Updated•3 years ago
|
Comment 5•3 years ago
|
||
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.
Updated•3 years ago
|
Updated•3 years ago
|
Assignee | ||
Comment 6•3 years ago
|
||
This is probably just the issue mentioned at https://github.com/tc39/ecma402/pull/575#pullrequestreview-730209467.
Assignee | ||
Comment 7•3 years ago
|
||
Updates SetNumberFormatDigitOptions
to the latest draft spec to correctly
handle compact notation with fractional digits.
Updated•3 years ago
|
Updated•3 years ago
|
Comment 9•3 years ago
|
||
bugherder |
Comment 10•3 years ago
|
||
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.
Assignee | ||
Updated•3 years ago
|
Updated•3 years ago
|
Comment 11•3 years ago
•
|
||
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.
Description
•