-
-
Notifications
You must be signed in to change notification settings - Fork 81
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 not working as expected #71
Comments
// @nmoinvaz |
@sindresorhus I am not doing well and will not be able to attend to this for some time. |
@nmoinvaz No worries at all. |
I have added some failing tests for this: 853dc19 |
As I tested in my I got same result:
There seems to be no fraction digit problems on my devices. I assume the rounding |
|
There is an ECMA proposal to support additional rounding options for |
Hey @sindresorhus, I've checked out the issue reported by @doomsower regarding the Issue Summary: Analysis:
Proposed Solution: // Format digits after the decimal point
const numString = number.toFixed(options.maximumFractionDigits); Given the current limitations and performance issues of Conclusion: Looking forward to your thoughts on this approach. Cheers, |
https://github.com/tc39/proposal-intl-numberformat-v3 states it was shipped in Chrome 106. I think it would be better just to add support for the rounding options |
@nmoinvaz sollution rocks! With the options suggested by him, when using minimumFractionDigits and maximumFractionDigits set to 1, the values now became consistent, look: // Tested on Node.js v21.6.1
Number(60.0000).toLocaleString('fr',{minimumFractionDigits: 0, maximumFractionDigits: 0, roundingMode: 'floor'})
// Returns: '60'
Number(60.0000).toLocaleString('fr',{minimumFractionDigits: 1, maximumFractionDigits: 1, roundingMode: 'floor'})
// Returns: '60,0'
Number(59.952784).toLocaleString('fr',{minimumFractionDigits: 1, maximumFractionDigits: 1, roundingMode: 'floor'})
// Returns: '59,9'
Number(59.952784).toLocaleString('fr',{minimumFractionDigits: 2, maximumFractionDigits: 2, roundingMode: 'floor'})
// Returns: '59,95' Following the NumberFormat docs, the only change needed to fix the problems mentioned would be to add |
This code
Results in following output:
I expect that both
max
andminMax
should be59.9 MB
.I'm using pretty-bytes@^5.6.0
The text was updated successfully, but these errors were encountered: