-
Notifications
You must be signed in to change notification settings - Fork 22.4k
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
Labels
closed: question
A user misinterpretation or support question. No action required.
Content:JS
JavaScript docs
Comments
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; |
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
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
en-us/web/javascript/reference/global_objects/intl/numberformat/numberformat
The text was updated successfully, but these errors were encountered: