You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formats can be supplied for numbers (as above) or for currencies or other units. They can also be used with ranges of numbers, resulting in formatting strings like “$10K” or “$3–7M”.
417
432
418
-
To format a number N, the greatest type less than or equal to N is used, with the appropriate plural category. N is divided by the type, after removing the number of zeros in the pattern, less 1. APIs supporting this format should provide control over the number of significant or fraction digits.
433
+
To format a number N, use the following steps:
434
+
435
+
Notes:
436
+
- A _letter grapheme cluster_ is a grapheme cluster that starts with a letter and then 0 or more combining marks.
437
+
For example, each of the following are are _letter grapheme clusters_: \<q>, \<q, _combining ring above_>, \<q, _combining ring above_, _acute accent_>.
438
+
- All of the pattern elements with the same type must have the same number of zeros in the pattern element value.
439
+
- The examples use N = 123456, the currency = CAD, and the currency symbol string = "$CA"
440
+
441
+
1. Let P be the pattern element with greatest type less than or equal to N, and any count value.
442
+
* P = `<pattern type="100000" count="**one**">¤000K</pattern>`
443
+
2. Let V be the pattern element value.
444
+
* V = "¤000K"
445
+
3. If the element value of P is "0", then use the corresponding non-compact number formatting instead, and skip the rest of these steps — but adjust the precision as described below.
446
+
* For example, instead of `currencyFormat``<pattern type="10000" count="one">¤00K</pattern>`, use `<pattern>¤#,##0.00</pattern>`.
447
+
4. If P is a currency format, look at the currency symbol string, and the position of the currency symbol ¤ in the pattern element value.
448
+
If ¤ is immediately to the left of a 0 and the currency string ends with a _letter grapheme cluster_ (eg, "$CA"),
449
+
or to the right and the currency starts with a letter (eg, "CA$"),
450
+
then switch to the `alt=alphaNextToNumber` pattern, if there is one.
451
+
* P = `<pattern type="100000" count="**one**" alt="alphaNextToNumber">¤ 000K</pattern>` // with the currency symbol "CA$"
452
+
* V = "¤ 000K"
453
+
5. Let Z be the number of 0 characters in V, minus 1.
454
+
* Z = 2
455
+
6. Let T be the numeric value of the `type` attribute value, after removing the final Z zeros.
456
+
* "100000" removing "00" = "1000"
457
+
* T = 1000
458
+
7. Let N' be N / T
459
+
* N = 123.456
460
+
8. Determine the plural category of N, based on the numeric precision settings (the min/max number of significant or fraction digits), and switch the value of V if necessary.
461
+
* In this case, the plural category of 123.456 in English with any precision is "other", so the
462
+
* P = `<pattern type="100000" count="**other**" alt="alphaNextToNumber">¤ 000K</pattern>`
463
+
* V = "¤ 000K"
464
+
* For the short compact formats, it doesn't make a difference for English, but may for other locales!
465
+
9. Let V' be the same as V, but replacing that sequence of zeros by "{0}".
466
+
* V' = "¤ {0}K"
467
+
10. Let F be N' formatted according to V' and the numeric precision settings.
468
+
* F = "$CA 123K" // where the precision is min = max = 3 significant digits
469
+
* F = "$CA 123.4K" // where the precision is min = max = 1 fraction digit
470
+
419
471
420
472
The default pattern for any type that is not supplied is the special value “0”, as in the following. The value “0” must be used when a child locale overrides a parent locale to drop the compact pattern for that type and use the default pattern.
421
473
@@ -427,7 +479,8 @@ With the data above, N=12345 matches `<pattern type="10000" count="other">00 K</
427
479
428
480
Formatting 1200 in USD would result in “1.2 K $”, while 990 implicitly maps to the special value “0”, which maps to `<currencyFormat type="standard"><pattern>#,##0.00 ¤</pattern>`, and would result in simply “990 $”.
429
481
430
-
The short format is designed for UI environments where space is at a premium, and should ideally result in a formatted string no more than about 6 em wide (with no fractional digits).
482
+
The short non-currency format is designed for UI environments where space is at a premium, and should ideally result in a formatted string no more than about 6 em wide (with no fractional digits).
483
+
The short currency format will include currency symbols, and should ideally be no more than 8 em in width.
0 commit comments