Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maximumFractionDigits has no effect #26213

Closed
ygoe opened this issue Apr 14, 2023 · 1 comment
Closed

maximumFractionDigits has no effect #26213

ygoe opened this issue Apr 14, 2023 · 1 comment
Labels
closed: question A user misinterpretation or support question. No action required. Content:JS JavaScript docs

Comments

@ygoe
Copy link
Contributor

ygoe commented Apr 14, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

What specific section or headline is this issue about?

maximumFractionDigits option

What information was incorrect, unhelpful, or incomplete?

The documentation explains that an option called maximumFractionDigits can be set and will be used accordingly. But I cannot observe this behaviour in any browser. It's ignored when set in the constructor, so I assume it cannot be configured.

What did you expect to see?

Here's a simple test case for the console:

new Intl.NumberFormat({ maximumFractionDigits: 5 }).resolvedOptions().maximumFractionDigits

This should return 5 but it returns its default value of 3. And the number formatting also caps at 3 decimals at most.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

I want to format numbers with 1 to 5 decimals, depending on the size. None of the NumberFormat options can do this, and they even fail with manual configuration. So I guess I'll have to implement it myself, taking the decimal separator from my existing texts dictionary and using simple Math.round() and String.replace() as needed.

MDN metadata

Page report details
@ygoe ygoe added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Apr 14, 2023
@github-actions github-actions bot added the Content:JS JavaScript docs label Apr 14, 2023
@Josh-Cena
Copy link
Member

Hi! The options must be passed as the second parameter. The first parameter is the locale. You can get the right result if you pass a locale:

new Intl.NumberFormat("en-US", { maximumFractionDigits: 5 }).resolvedOptions().maximumFractionDigits;
new Intl.NumberFormat([], { maximumFractionDigits: 5 }).resolvedOptions().maximumFractionDigits;
new Intl.NumberFormat(undefined, { maximumFractionDigits: 5 }).resolvedOptions().maximumFractionDigits;

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Apr 14, 2023
@Josh-Cena Josh-Cena added the closed: question A user misinterpretation or support question. No action required. label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: question A user misinterpretation or support question. No action required. Content:JS JavaScript docs
Projects
None yet
Development

No branches or pull requests

2 participants