-
Notifications
You must be signed in to change notification settings - Fork 104
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
Support additional scientific notation styles? #362
Comments
And if you have units, SI-prefixes may be the way to go. |
ICU has this functionality in http://icu-project.org/apiref/icu4c/classicu_1_1ScientificNumberFormatter.html |
Btw, what MathML to use for a number in scientific notation, like 1.23×10⁻⁴ ? |
If we directly expose |
Another point: you can use const nf = new Intl.NumberFormat("es-MX", { notation: "scientific" });
nf.formatToParts(5.55e-4);
/*
[
{"type":"integer","value":"5"},
{"type":"decimal","value":"."},
{"type":"fraction","value":"55"},
{"type":"exponentSeparator","value":"E"},
{"type":"exponentMinusSign","value":"-"},
{"type":"exponentInteger","value":"4"}
]
*/ You can search for "exponentSeparator" and replace it with "×10", and then wrap the "exponentMinusSign" and "exponentInteger" in |
This, on the other hand, seems too low level to me. I suppose atleast html (not quite sure about mathml yet, but I suppose that too) is a common enough use-case to be easier to achieve? |
I demonstrated that it's possible today for someone to write a small library on top of the existing Intl.NumberFormat that mostly works. That violates point 3 in API surface guidelines I proposed in #442 (comment). That being said, this feature could still move forward, but we should have a compelling case that there are a lot of users who would benefit from this feature, and that it is sufficiently difficult to implement in user land that it belongs in the standard library. |
I hadn't realized that this wasn't a WIP. I don't feel strongly enough about it unless we go ahead and add the others, thanks for the clarification. |
|
Another variant is to extract the exponent from the number and format the coefficient and the exponent separately. Well... The accuracy will be lost for some numbers. |
Based on #164, we are adding scientific notation via
{ notation: "scientific" }
. We are using the LDML format for the output, which is1.23E4
Based on a localizable pattern and exponent separator:
However, this is not necessarily the most "human-friendly" scientific format. Users might expect something like the following:
1.23×10⁴
Users may also prefer to use HTML tags for the superscript. This also helps support non-Latin numbering systems since the superscript digits are only available in Latin.
1.23×10<sup>4</sup>
This could be specified by a new field like scientificDisplay, similar to compactDisplay.
The text was updated successfully, but these errors were encountered: