Number & Currency formatting
CLDR defines many different ways to format a number for different uses and defines a set of formats categorised by common pupose to make it easier to express the same intent across many different locales that represent many different territories, cultures, number systems and scripts.
See Cldr.Number and Cldr.Number.to_string/2
Formatting Styles
Cldr supports the styles of formatting defined by CLDR being:
standardwhich formats a number if a decimal format commonly used in many locales.currencywhich formats a number according to the format or a particular currency adjusted for rounding, number of decimal digits after the fraction, whether the currency is accounting or cash rounded and using the appropriate locale-specific currency symbol.accountingwhich formats a positive number likestandardbut which usually wraps a negative number in().percentwhich multiplies a number by 100 and includes a locale-specific percent symbol. Usually%.permillewhich multiples a number by 1,000 and includes a locale specific permille symbol. Usually‰.scientificwhich formats a number as a mantissa and base-10 exponent.
See Cldr.Number.Formatter.Decimal
Short & Long Formats
Cldr also supports formats that minimise publishing space or which attempt to make large number more human-readable.
decimal_shortwhich presents number is a narrow space. For example,1,000would be formatted as1k.decimal_longwhich presents numbers in a sentence form adjusted for plurality and locale. For example,1,0000would be formatted as1 thousand. This is not the same as spelling out the number which is part of the Unicode CLDR Rules-Based Number Formatting. This capability is not yet available inCldrcurrency_shortwhich formats a number in a manner similar todecimal_shortbut includes the symbol currency.currency_longwhich formats a number in a manner similar todecimal_longbut incudes the localised name of the current.
See Cldr.Number.Formatter.Short and Cldr.Number.Formatter.Currency.
User-Specified Decimal Formats
User-defined decimal formats are also supported using the formats described by Unicode technical report TR35.
The formats described therein are supported by Cldr with some minor omissions and variations. Some examples of number formats are:
| Pattern | Currency | Text |
|---|---|---|
| #,##0.## | n/a | 1 234,57 |
| #,##0.### | n/a | 1 234,567 |
| ###0.##### | n/a | 1234,567 |
| ###0.0000# | n/a | 1234,5670 |
| 00000.0000 | n/a | 01234,5670 |
| 00 | n/a | 12 |
| #,##0.00 ¤ | EUR | 1 234,57 € |
See Cldr.Number and Cldr.Number.Formatter.Decimal.