Part 3: Numbers

Version | 40 |

Editors | Shane F. Carr (shane@unicode.org) and other CLDR committee members |

- ;

No. | Replacement / Example |
---|---|

¤ | Standard currency symbol |

_C$12.00_ | |

¤¤ | ISO currency symbol (constant) |

_CAD 12.00_ | |

¤¤¤ | Appropriate currency display name for the currency,based on the plural rules in effect for the locale |

_5.00 Canadian dollars_ | |

¤¤¤¤¤ | Narrow currency symbol. The same symbols may be used for multiple currencies. Thus the symbol may be ambiguous, and should only be where the context is clear. |

_$12.00_ | |

_others_ | _Invalid in current CLDR. Reserved for future specification_ |

explicit pattern: | 0.00;-0.00 | 0.00;0.00- | 0.00+;0.00- | |||
---|---|---|---|---|---|---|

decimalSign: | , | , | , | |||

minusSign: | ∸ | ∸ | ∸ | |||

plusSign: | ∔ | ∔ | ∔ | |||

number: | 3.1415 | -3.1415 | 3.1415 | -3.1415 | 3.1415 | -3.1415 |

formatted: | 3,14 | ∸3,14 | 3,14 | 3,14∸ | 3,14∔ | 3,14∸ |

Original: | 1.234 |
---|---|

Divide by increment (0.65): | 1.89846… |

Round: | 2 |

Multiply by increment (0.65): | 1.3 |

1.00 gets the same category as 1. | | Visible | All visible fractions are in one category (typically ‘other’ = ‘plural). | 1.00, 1.01, 3.5 all get the same category. | | Digits | The visible fraction determines the category. | 1.13 gets the same class as 13. | There are also variants of the above: for example, short fractions may have the Digits behavior, but longer fractions may just look at the final digit of the fraction. #### Explicit 0 and 1 rules Some types of CLDR data (such as [unitPatterns](tr35-general.md#Unit_Elements) and [currency displayNames](#Currencies)) allow specification of plural rules for explicit cases “0” and “1”, in addition to the language-specific plural cases specified above: “zero”, “one”, “two” ... “other”. For the language-specific plural rules: * The rules depend on language; for a given language, only a subset of the cases may be defined. For example, English only defines “one” and “other”, cases like “two” and “few” cannot be used in plurals for English CLDR items. * Each plural case may cover multiple numeric values, and may depend on the formatting of those values. For example, in French the “one” case covers 0.0 through 1.99. * The “one” case, if defined, includes at least some formatted forms of the numeric value 1; the “zero” case, if defined, includes at least some formatted forms of the numeric value 0. By contrast, for the explicit cases “0” and “1”: * The explicit “0” and “1” cases are not defined by language-specific rules, and are available in any language for the CLDR data items that accept them. * The explicit “0” and “1” cases apply to the exact numeric values 0 and 1 respectively. These cases are typically used for plurals of items that do not have fractional value, like books or files. * The explicit “0” and “1” cases have precedence over the “zero” and “one” cases. For example, if for a particular element CLDR data includes values for both the “1” and “one” cases, then the “1” value is used for numeric values of exactly 1, while the “one” value is used for any other formatted numeric values matching the “one” plural rule for the language. Usage example: In English (which only defines language-specific rules for “one” and “other”) this can be used to have special behavior for 0: * count=“0”: no books * count=“one”: {0} book, e.g. “1 book” * count=“other”: {0} books, e.g. “3 books” ### 5.1 Plural rules syntax The xml value for each pluralRule is a _condition_ with a boolean result that specifies whether that rule (i.e. that plural form) applies to a given numeric value _n_, where n can be expressed as a decimal fraction or with compact decimal formatting, denoted by a special notation in the syntax, e.g., “1.2c6” for “1.2M”. Clients of CLDR may express all the rules for a locale using the following syntax: ``` rules = rule (';' rule)* rule = keyword ':' condition samples | 'other' ':' samples keyword = [a-z]+ keyword = [a-z]+ ``` In CLDR, the keyword is the attribute value of 'count'. Those values in CLDR are currently limited to just what is in the DTD, but clients may support other values. The conditions themselves have the following syntax. ``` condition = and_condition ('or' and_condition)* samples = ('@integer' sampleList)? ('@decimal' sampleList)? and_condition = relation ('and' relation)* relation = is_relation | in_relation | within_relation is_relation = expr 'is' ('not')? value in_relation = expr (('not')? 'in' | '=' | '!=') range_list within_relation = expr ('not')? 'within' range_list expr = operand (('mod' | '%') value)? operand = 'n' | 'i' | 'f' | 't' | 'v' | 'w' | 'c' | 'e' range_list = (range | value) (',' range_list)* range = value'..'value value = digit+ sampleList = sampleRange (',' sampleRange)* (',' ('…'|'...'))? sampleRange = sampleValue ('~' sampleValue)? sampleValue = value ('.' digit+)? ([ce] digitPos digit+)? digit = [0-9] digitPos = [1-9] ``` * Whitespace (defined as Unicode [Pattern_White_Space](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5Cp%7BPattern_White_Space%7D)) can occur between or around any of the above tokens, with the exception of the tokens in value, digit, and decimalValue. * In the syntax, **and** binds more tightly than **or**. So **X or Y and Z** is interpreted as **(X or (Y and Z))**. * Each plural rule must be written to be self-contained, and not depend on the ordering. Thus rules must be mutually exclusive; for a given numeric value, only one rule can apply (i.e., the condition can only be true for one of the pluralRule elements. Each keyword can have at most one condition. The 'other' keyword must have an empty condition: it is only present for samples. * The samples should be included, since they are used by client software for samples and determining whether the keyword has finite values or not. * The 'other' keyword must have no condition, and all other keywords must have a condition. #### 5.1.1 Operands The operands correspond to features of the source number, and have the following meanings. ##### Plural Operand Meanings | Symbol | Value | | --- | --- | | n | absolute value of the source number. | | i | integer digits of n. | | v | number of visible fraction digits in n, _with_ trailing zeros.* | | w | number of visible fraction digits in n, _without_ trailing zeros.* | | f | visible fraction digits in n, _with_ trailing zeros.* | | t | visible fraction digits in n, _without_ trailing zeros.* | | c | compact decimal exponent value: exponent of the power of 10 used in compact decimal formatting. | | e | currently, synonym for ‘c’. however, may be redefined in the future. | \* If there is a compact decimal exponent value (‘c’), then the f, t, v, and w values are computed _after_ shifting the decimal point in the original by the ‘c’ value. So for 1.2c3, the f, t, v, and w values are the same as those of 1200: i=1200 and f=0. Similarly, for 1.2005c3 has i=1200 and f=5 (corresponding to 1200.5). ##### Plural Operand Examples | source | n | i | v | w | f | t | e | | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | | 1.0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | | 1.00 | 1 | 1 | 2 | 0 | 0 | 0 | 0 | | 1.3 | 1.3 | 1 | 1 | 1 | 3 | 3 | 0 | | 1.30 | 1.3 | 1 | 2 | 1 | 30 | 3 | 0 | | 1.03 | 1.03 | 1 | 2 | 2 | 3 | 3 | 0 | | 1.230 | 1.23 | 1 | 3 | 2 | 230 | 23 | 0 | | 1200000 | 1200000 | 1200000 | 0 | 0 | 0 | 0 | 0 | | 1.2c6 | 1200000 | 1200000 | 0 | 0 | 0 | 0 | 6 | | 123c6 | 123000000 | 123000000 | 0 | 0 | 0 | 0 | 6 | | 123c5 | 12300000 | 12300000 | 0 | 0 | 0 | 0 | 5 | | 1200.50 | 1200.5 | 1200 | 2 | 1 | 50 | 5 | 0 | | 1.20050c3 | 1200.5 | 1200 | 2 | 1 | 50 | 5 | 3 | #### 5.1.2 Relations The positive relations are of the format **x = y** and **x = y mod z**. The **y** value can be a comma-separated list, such as **n = 3, 5, 7..15**, and is treated as if each relation were expanded into an OR statement. The range value **a..b** is equivalent to listing all the _**integers**_ between **a** and **b**, inclusive. When **!=** is used, it means the entire relation is negated. ##### Relations Examples | Expression | Meaning | | --- | --- | | x = 2..4, 15 | x = 2 OR x = 3 OR x = 4 OR x = 15 | | x != 2..4, 15 | NOT (x = 2 OR x = 3 OR x = 4 OR x = 15) | | Expression | Value | | --- | --- | | 3.5 = 2..4, 15 | false | | 3.5 != 2..4, 15 | true | | 3 = 2..4, 15 | true | | 3 != 2..4, 15 | false | > The old keywords 'mod', 'in', 'is', and 'within' are present only for backwards compatibility. The preferred form is to use '%' for modulo, and '=' or '!=' for the relations, with the operand 'i' instead of within. (The difference between **in** and **within** is that **in** only includes integers in the specified range, while **within** includes all values.) The modulus (% or **mod**) is a remainder operation as defined in Java; for example, where **n** = 4.3 the result of **n mod 3** is 1.3. The values of relations are defined according to the operand as follows. Importantly, the results may depend on the visible decimals in the source, including trailing zeros, and the compact decimal exponent. 1. Let the base value BV be computed from absolute value of the original source number according to the operand. 2. Let R be false when the comparison contains ‘not’. 3. Let R be !R if the comparison contains ‘within’ and the source number is not an integer. 4. If there is a module value MV, let BV be BV - floor(BV/MV). 5. Let CR be the list of comparison ranges, normalized that overlapping ranges are merged. Single values in the rule are represented by a range with identical \

few: n = 2..4 | This defines two rules, for 'one' and 'few'. The condition for 'one' is "n = 1" which means that the number must be equal to 1 for this condition to pass. The condition for 'few' is "n = 2..4" which means that the number must be between 2 and 4 inclusive for this condition to pass. All other numbers are assigned the keyword 'other' by the default rule. | | zero: n = 0 or n != 1 and n mod 100 = 1..19

one: n = 1 | Each rule must not overlap with other rules. Also note that a modulus is applied to n in the last rule, thus its condition holds for 119, 219, 319… | | one: n = 1

few: n mod 10 = 2..4 and n mod 100 != 12..14 | This illustrates conjunction and negation. The condition for 'few' has two parts, both of which must be met: "n mod 10 = 2..4" and "n mod 100 != 12..14". The first part applies a modulus to n before the test as in the previous example. The second part applies a different modulus and also uses negation, thus it matches all numbers _not_ in 12, 13, 14, 112, 113, 114, 212, 213, 214… | #### 5.1.3 Samples Samples are provided if sample indicator (@integer or @decimal) is present on any rule. (CLDR always provides samples.) Where samples are provided, the absence of one of the sample indicators indicates that no numeric values can satisify that rule. For example, the rule "i = 1 and v = 0" can only have integer samples, so @decimal must not occur. The @integer samples have no visible fraction digits, while @decimal samples have visible fraction digits; both can have compact decimal exponent values (if the 'e' operand occurs). The sampleRanges have a special notation: **start**~**end**. The **start** and **end** values must have the same number of decimal digits, and the same compact decimal exponent values (or neither have compact decimal exponent values). The range encompasses all and only values those value **v** where **start ≤ v ≤ end**, and where **v** has the same number of decimal places as **start** and **end**, and the same compact decimal exponent values. Samples must indicate whether they are infinite or not. The '…' marker must be present if and only infinitely many values (integer or decimal) can satisfy the rule. If a set is not infinite, it must list all the possible values. ##### Plural Samples Examples | Rules | Comments | | --- | --- | | @integer 1, 3~5 | 1, 3, 4, 5. | | @integer 3\~5, 103\~105, … | Infinite set: 3, 4, 5, 103, 104, 105, … | | @decimal 1.3\~1.5, 1.03\~1.05, … | Infinite set: 1.3, 1.4, 1.5, 1.03, 1.04, 1.05, … | In determining whether a set of samples is infinite, leading zero integer digits and trailing zero decimals are not significant. Thus "i = 1000 and f = 0" is satisfied by 01000, 1000, 1000.0, 1000.00, 1000.000, 01c3 etc. but is still considered finite. #### 5.1.4 Using Cardinals Elements such as `