-
Notifications
You must be signed in to change notification settings - Fork 106
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
Allow passing in string to NumberFormat.prototype.format()
#407
Comments
NumberFormat.prototype.format()
NumberFormat.prototype.format()
@littledan added BigInt formatting support in #236. He is also championing a Stage 1 proposal for high-precision decimals. Those proposals should cover most of the bases. That being said, a smaller feature which could serve this use case would be a Example: let num = 987654321n;
let fmt = new Intl.NumberFormat("en-US", { scale: -2 });
fmt.format(num);
// 9,876,543.21 Note that formatting with |
I don't understand why it all needs to be that complicated. Based on my review of a prominent polyfill, the very first thing the code does is cast the number to a string anyway. It therefore follows that it should be easy to just accept strings directly. |
There are several problems with accepting strings as part of the spec:
Better would be if we had a first-class ECMAScript type for high-precision decimals, which is what @littledan's proposal does, and as a fallback, the BigInt+scale approach gets the job done and is not too bad. Example of the status quo accepting strings: const nf = new Intl.NumberFormat();
nf.format("123456789123456789123"); // "123,456,789,123,456,800,000" |
About 1. That being said, I like the BigInt+scale approach better. |
Closing as a dupe of #334 |
It would be great to be able to pass in a string in the format
\d+\.\d*
(or something along those lines) and have the number formatter work with it. Right now there's no support for very large numbers, either fromBigInt
or from a third-party "big number" library likebignumber.js
. At the very least, the latter provides functionality to retrieve the full precision number in a non-locale-dependent string form, which should be perfect for passing in to the number formatter.The text was updated successfully, but these errors were encountered: