Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  179] [ 4]  / answers: 1 / hits: 5457  / 4 Years ago, fri, march 6, 2020, 12:00:00

I'm trying to use the example given here concerning formatting a number.





console.log((16).toLocaleString('en-GB', {
style: unit,
unit: liter,
unitDisplay: long
}));





I tried it in chrome and it works great. However, in Safari as well as Firefox I get the following errors respectively Error: style must be either decimal, percent, or currency and Error: invalid value unit for option style.



From the docs I figured it should work on all browsers after looking at the browser compatibility. I tried looking for answers, but I can't find anything regarding this issue. Does anyone know why this is or where I could probably find more info?


More From » firefox

 Answers
1

The problem comes from the value unit of the style field.



According to ECMA-402, 6th edition, June 2019
ECMAScript® 2019 Internationalization API Specification
:




The value of this field must be a record, which must have fields with the names of the three number format styles: decimal, percent, and currency.




According to the Draft ECMA-402 / February 27, 2020
ECMAScript® 2020 Internationalization API Specification
:




The value of this field must be a Record, which must have fields with the names of the four number format styles: decimal, percent, currency, and unit.




Firefox and Safari are implementing the 6th edition of the ECMA-402 specification and Chrome is implementing the Draft version of this same specification. The draft specification can change at any time and there is no formal guarantees that this new unit value will be included in the 7th edition. If you want to be cross-browser compatible and future-proof, you should stick on the 6th edition and wait for the release of the 7th edition before using these new features.



If you want details you can read the proposition for this new feature.


[#4560] Monday, March 2, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
payne questions
Thu, Sep 3, 20, 00:00, 4 Years ago
Tue, Aug 18, 20, 00:00, 4 Years ago
Thu, Oct 11, 18, 00:00, 6 Years ago
Mon, Mar 5, 18, 00:00, 6 Years ago
;