Shelves / Internationalisation
IN·04
Locales: Numbers, Currencies, Plurals and Money
What a locale is and how software picks one: BCP 47 tags, negotiation and fallback, and the CLDR data behind every platform; formatting and parsing numbers (lakh and crore grouping, separators, native digits), dates, units, lists and relative times; plural rules from English's two forms to Arabic's six; currencies, minor units and exchange rates; and exact money arithmetic, rounding modes, allocation and tax; with a lab in Node.js Intl and Python that formats one number seven ways and loses paise with floats.
Start here: one number, seven answers
The lab formatted 12,345,678.5 and ₹123,456.50 with Node.js's Intl (which uses CLDR data through ICU):
| Locale | Number | Money |
|---|---|---|
en-IN |
1,23,45,678.5 | ₹1,23,456.50 |
en-US |
12,345,678.5 | $123,456.50 (USD) |
de-DE |
12.345.678,5 | 123.456,50 € (EUR) |
fr-FR |
12 345 678,5 (narrow spaces) | |
ar-EG |
١٢٬٣٤٥٬٦٧٨٫٥ (Arabic-Indic digits) | |
ja-JP |
12,345,678.5 | ¥123,456 (JPY: no decimals) |
ar-KW |
١٢٣٫٤٥٦ د.ك. (KWD: three decimals) |
In compact form the same 13 million is 1.3Cr (crore) in en-IN and 13M in en-US.
Then it asked how many items needed which word form. English has two plural forms; the others:
| Language | Category for 0, 1, 2, 5, 11, 100 | Categories in all |
|---|---|---|
| English | other, one, other, other, other, other | one, other |
| Hindi | one, one, other, other, other, other | one, other |
| French | one, one, other, other, other, other | one, many, other |
| Russian | many, one, few, many, many, many | one, few, many, other |
| Arabic | zero, one, two, few, many, other | six |
| Japanese | other × 6 | other |
And money in floating point: adding ₹0.10 a million times gave 100000.00000133288; round(2.675, 2) gave 2.67; splitting ₹100 three ways in paise lost 1 paisa unless the remainder was allocated.
Locale data is too large and too subtle to hand-code. This chapter shows what's in it, how to use it, and how to compute money exactly.
How deep to go
Volume 17 defines six mastery levels. For locales and money:
| Level | What you can do |
|---|---|
| L1 | Format numbers, dates and currencies with the platform's locale APIs |
| L2 | Pluralise correctly; parse user-entered numbers; store money exactly |
| L3 | Explain locale tags, negotiation, CLDR data, plural rules, minor units and rounding modes |
| L4 | Diagnose formatting, parsing, rounding and reconciliation errors |
| L5 | Design multi-currency pricing, tax and settlement with correct rounding and audit trails |
| L6 | Contribute locale data or build money and tax engines across many jurisdictions |
Locales
Tags
Locales are written as BCP 47 language tags:
language[-script][-region][-variant][-u-extensions]
hi Hindi
hi-IN Hindi, India
hi-Latn-IN Hindi in Latin script, India
zh-Hant-TW Chinese, Traditional script, Taiwan
sr-Cyrl / sr-Latn Serbian in Cyrillic / Latin
en-IN-u-nu-deva English (India) with Devanagari digits
ar-SA-u-ca-islamic Arabic (Saudi Arabia), Islamic calendar
en-GB-u-hc-h23 British English, 24-hour clock
Language codes come from ISO 639, scripts from ISO 15924, regions from ISO 3166 (or UN M.49 numbers like 419 for Latin America). Use - not _ in tags (en_US is a POSIX locale name, not BCP 47).
Negotiation and fallback
A user has an ordered list of preferences (from the OS, Accept-Language, or an in-app setting); you have the locales you support. Negotiation picks the best match, and fallback fills gaps:
- Matching isn't string equality: a user asking for
en-AUshould geten-GB(closer conventions) rather thanen-USif you have both;pt-BRandpt-PTdiffer enough to treat separately. ICU'sLocaleMatcherand the@formatjs/intl-localematcherpackage implement CLDR's distance data. - Fallback for messages goes
ta-IN→ta→ the default language. Untranslated strings should fall back per message, not the whole screen. - Keep language and region settings separate where they matter: a Telugu speaker in New Jersey wants Telugu text, US dollars, and dates possibly in either convention; let them choose.
- Don't infer language from IP address or country: India has 22 scheduled languages and most users read English; an IP in the UAE may be a Malayalam speaker.
CLDR: the data behind it all
The Unicode Common Locale Data Repository holds, for about 1,000 locales: number formats and digits, currency symbols and decimals, date and time patterns, month and day names, calendars, plural and ordinal rules, list patterns, relative-time words, unit names, collation tailorings (chapter 02), time-zone names, territory and language names, week conventions and more. ICU implements it; so do Android, iOS, Java, browsers (Intl), Node.js, PostgreSQL ICU collations and most i18n libraries. Two consequences: results can change between versions (format output is for humans, never parse it back or snapshot-test it exactly), and the device's CLDR version may differ from the server's.
Formatting and parsing numbers
| Locale feature | Examples |
|---|---|
| decimal separator | . (en), , (de, fr, ru), ٫ (ar) |
| grouping separator | , (en), . (de), narrow no-break space (fr), ' (de-CH) |
| grouping sizes | 3 (most); 3 then 2 in Indian locales: 1,23,45,678 |
| digits | Latin 0–9; Arabic-Indic ٠–٩ (ar-EG); Devanagari ०–९ available via -u-nu-deva |
| percent | 50% (en), 50 % (de, fr), %50 (tr) |
| compact | 1.3Cr / 13 lakh (en-IN), 13M (en-US), 1.3 क॰ (hi-IN) |
Use the platform: Intl.NumberFormat, java.text.NumberFormat / android.icu.number.NumberFormatter, Swift's formatted(), Python's Babel. Never build numbers by concatenation or toFixed() for display.
Parsing user input is harder than formatting. "1.234" is one thousand two hundred thirty-four in German and one point two three four in English. Rules that work:
- Use input types that help:
inputmode="decimal"on the web, number keyboards on mobile. - Parse with the user's locale (
NumberFormat.parse, Babel'sparse_decimal), and accept native digits (Arabic-Indic, Devanagari) by normalising them to ASCII digits. - Show the parsed value back ("₹1,234.00") before committing anything important.
- In APIs, files and databases, use a locale-independent format (JSON numbers,
.decimal, no grouping), and money as strings or integer minor units.
Units and measurement systems
The US uses miles, pounds, Fahrenheit, cups; most of the world is metric; the UK mixes (miles and pints, kg and °C). Intl.NumberFormat with style: 'unit' formats units by locale (2.5 km, 2,5 km), but which unit to use is a product decision: store in a base unit (grams, metres, Celsius) and convert for display by region preference.
Plurals, ordinals, lists and relative times
Plural rules
CLDR defines up to six plural categories: zero, one, two, few, many, other. Each language maps numbers to categories with rules:
- English:
onefor 1,otherfor everything else (including 0: "0 items"). - Hindi:
onefor 0 and 1. - French:
onefor 0 and 1;manyfor large round numbers like 1,000,000 ("1 million de repas"). - Russian, Polish: by the last digits: 1 → one, 2–4 → few, 5–20 → many, 21 → one, 22 → few, and so on (Polish differs in detail).
- Arabic: all six.
- Japanese, Chinese, Korean, Thai: only
other.
Categories are not numbers: "one" in Russian includes 21, 31, 101. The code asks new Intl.PluralRules('ru').select(n) and picks the message variant (chapter 05 shows how messages express this). Plural rules depend on the number as displayed: "1.0 kg" may be other in English.
Ordinals (1st, 2nd, 3rd, 4th; 21st, 22nd) have their own rules: new Intl.PluralRules('en', {type: 'ordinal'}) gives one/two/few/other for English. Many languages simply use a different word form.
Lists and relative times
Intl.ListFormat joins lists by locale: "curd rice, sambar, and papad" (en-US, with the Oxford comma), "दही चावल, सांबर, और पापड़" (hi). Intl.RelativeTimeFormat gives "yesterday", "in 2 hours", and words like Hindi कल, which means both "yesterday" and "tomorrow" (the context of the sentence decides). Use these APIs rather than templates such as "{n} hours ago".
Intl.DisplayNames gives names of languages, regions and currencies in the user's language ("తెలుగు", "Indian Rupee", "भारतीय रुपया"), for pickers and settings.
Currencies
- Identify currencies by ISO 4217 codes:
INR,USD,AED,EUR,JPY,KWD. Symbols are ambiguous ($is US, Canadian, Australian, Singapore and more dollars;krseveral crowns). - Minor units differ: 2 for most (paise, cents, fils in AED), 0 for JPY and KRW, 3 for KWD, BHD, OMR. Some currencies' cash differs from accounting precision (CHF cash rounds to 0.05). Read minor units from ISO data (
Intl.NumberFormat().resolvedOptions().maximumFractionDigitsfor a currency, or a currency library), not a hard-coded 2. - Formatting is the viewer's; currency is the amount's. A Hyderabad kitchen's ₹149 shown to a user with locale
en-USis "₹149.00", not "$149". If you show a converted estimate, label it ("≈ $1.79") and charge in the actual currency. - Exchange rates change constantly. Store, with every converted amount, the source amount and currency, the rate, its source and timestamp. Convert once at a defined moment (checkout, settlement) and never recompute history with today's rate.
Money arithmetic
Representation
| Option | Use | Notes |
|---|---|---|
integer minor units (14900 paise) |
storage, APIs, most arithmetic | exact; needs the currency to know the scale; watch overflow with 32-bit integers |
decimal type (NUMERIC(19,4), BigDecimal, Python Decimal) |
calculations with fractional intermediate values (tax rates, unit prices, FX) | exact decimal; you choose scale and rounding explicitly |
| float/double | never for money | 0.1 + 0.2 = 0.30000000000000004 |
The lab: adding ₹0.10 one million times with floats gave 100000.00000133288; the same in integer paise gave exactly ₹1,00,000. round(2.675, 2) in Python returned 2.67 because the float closest to 2.675 is 2.67499999…
JSON numbers are doubles in JavaScript; send money as integer minor units with a currency code ({"amount": 14900, "currency": "INR"}) or as a decimal string ("149.00").
Rounding
Every rounding is a business rule; write it down.
| Mode | 0.125 → 2 places | 0.135 | Use |
|---|---|---|---|
| half-up | 0.13 | 0.14 | common consumer expectation; many tax rules |
| half-even (banker's) | 0.12 | 0.14 | default in many libraries (Python Decimal, Java HALF_EVEN); unbiased over many roundings |
| down / up (toward or away from zero) | 0.12 / 0.13 | specific regulations, conservative estimates |
Where you round matters as much as how. The lab computed 18% GST on ten items of ₹12.35: rounding per line gave ₹22.20 (₹2.22 × 10), rounding the total gave ₹22.23. Tax laws and accounting policies say which applies (per invoice line or per invoice), and both the customer's receipt and the accounting ledger must agree.
Allocation
Splitting an amount (a ₹100 refund across three kitchens, a discount across lines) must preserve the total. Divide, round down, then give the leftover minor units one at a time (to the largest shares, or by a stated rule). The lab: naive division gave [3333, 3333, 3333] paise, a total of 9,999; allocation gave [3334, 3333, 3333]. Libraries such as Java Money (JSR 354), Python py-moneyed, and dinero.js include allocation.
Ledgers
Money that moves is recorded as double-entry ledger rows (every debit has an equal credit), in the amount's currency, with immutable history and corrections as new entries (Volume 19's payments chapter). Multi-currency ledgers keep each currency in its own balance and record FX conversions as explicit entries.
Common traps
- Concatenating numbers and units by hand.
- Hard-coding 2 decimal places for every currency.
- Assuming the user's locale implies the currency.
- Floats for money, anywhere (including JSON in JavaScript).
- Rounding at an unstated point, so totals and lines disagree.
- Splitting amounts without allocating the remainder.
n == 1 ? "item" : "items"as plural logic.- Parsing numbers with one locale's separators.
- Snapshot tests on formatted output that break with CLDR updates.
Lab: formatting and exact money
Setup. Two scripts on the lab machine. fmt.js runs on Node.js 22, whose Intl APIs use ICU with full CLDR data; it formats a number, currency amounts, compact numbers and a date in several locales, prints plural categories with Intl.PluralRules, and formats a list and relative times. money.py uses Python 3.13's floats, integers and decimal. The date line shows the time the script ran; everything else is fixed input.
Results: formatting
| Locale | 12345678.5 | Currency amount 123456.5 |
|---|---|---|
| en-IN | 1,23,45,678.5 | INR ₹1,23,456.50 |
| hi-IN | 1,23,45,678.5 | INR ₹1,23,456.50 |
| en-US | 12,345,678.5 | USD $123,456.50 |
| de-DE | 12.345.678,5 | EUR 123.456,50 € |
| fr-FR | 12 345 678,5 | |
| ar-EG | ١٢٬٣٤٥٬٦٧٨٫٥ | |
| ja-JP | 12,345,678.5 | JPY ¥123,456 (0 decimals) |
| ar-KW | KWD ١٢٣٫٤٥٦ د.ك. (3 decimals) |
- Compact 13,000,000: en-IN 1.3Cr, en-US 13M, hi-IN 1.3 क॰.
- Dates (same instant): en-IN
5 Nov 2026, 12:12 pm; en-USNov 5, 2026, 12:12 PM; en-GB5 Nov 2026, 12:12; de-DE05.11.2026, 12:12; ta-IN5 நவ., 2026, 12:12 PM; ja-JP2026/11/05 12:12. - List:
curd rice, sambar, and papad/दही चावल, सांबर, और पापड़. - Relative: en "yesterday"; hi कल; ta "2 மணிநேரத்தில்" (in 2 hours).
Results: plural categories for 0, 1, 2, 5, 11, 100
| Language | Categories selected | All categories |
|---|---|---|
| en | other, one, other, other, other, other | one, other |
| hi | one, one, other, other, other, other | one, other |
| fr | one, one, other, other, other, other | one, many, other |
| ru | many, one, few, many, many, many | one, few, many, other |
| ar | zero, one, two, few, many, other | zero, one, two, few, many, other |
| pl | many, one, few, many, many, many | one, few, many, other |
| ja | other × 6 | other |
Results: money
| Test | Result |
|---|---|
0.1 + 0.2 |
0.30000000000000004 |
| ₹0.10 added 1,000,000 times as float | 100000.00000133288 |
| the same in integer paise | 10,000,000 paise = ₹1,00,000 exactly |
round(2.675, 2) |
2.67 (2.675 is stored as 2.67499999…) |
| ₹100 ÷ 3, naive in paise | [3333, 3333, 3333], sum 9,999 |
| ₹100 ÷ 3, allocated | [3334, 3333, 3333], sum 10,000 |
| 18% GST on 10 × ₹12.35, per line | ₹22.20 |
| the same, on the total | ₹22.23 |
| 0.125 half-even / half-up | 0.12 / 0.13 |
What it shows
- Locale data covers far more than translations: grouping, digits, decimals per currency, compact forms, date patterns, plural rules and list words.
- Plural categories vary from one to six, and "0" isn't plural in every language.
- Floats lose money, slowly and invisibly; integers and decimals don't.
- Where you round and how you allocate change totals, so they must be specified rules.
Try it yourself
- Format 1, 2, 5, 21, 22 and 25 with
Intl.PluralRules('ru')and write the Russian for "N meals" for each category. - Parse "1.234,5" and "1,234.5" with Babel in
de_DEanden_IN. What happens to the wrong one? - Write
allocate(amount_minor, ratios)that splits ₹999.99 in the ratio 1:2:3 and always preserves the total. - Change the GST example to rounding half-even per line, then half-up on the total, for 1 to 20 items: how often do they disagree?
- Format ₹1,49,000 for a user whose locale is
en-USand forhi-IN-u-nu-deva.
Revision sheet: locales, numbers, currencies, plurals and money
Key ideas
- BCP 47 tags: language-script-region plus
-u-extensions (numbering system, calendar, hour cycle, collation). - Negotiate locales with distance-aware matching; fall back per message; keep language and region choices separate; don't infer language from IP.
- CLDR (via ICU) provides number, date, currency, plural, list, relative-time and name data; output changes between versions.
- Format with platform APIs; parse input with the user's locale and show it back; exchange data in locale-neutral formats.
- Plural categories: zero, one, two, few, many, other; ordinals have their own rules.
- Currency belongs to the amount; formatting belongs to the viewer; minor units vary (0, 2, 3).
- Money: integer minor units or decimals, never floats; stated rounding modes and points; allocate remainders; store FX rate and time with conversions.
Numbers to remember
- Indian grouping 1,23,45,678; 1 lakh = 100,000; 1 crore = 10,000,000.
- Minor units: JPY 0, INR 2, KWD 3.
- Lab: 1 million float additions of 0.10 drifted by 0.0000013; GST per line ₹22.20 vs total ₹22.23.
Glossary
- BCP 47: the standard for language tags.
- CLDR / ICU: locale data and the library implementing it.
- Plural category: a CLDR class of numbers needing one word form.
- ISO 4217: currency codes and minor units.
- Minor unit: the smallest currency unit (paisa, cent, fils).
- Half-even rounding: ties round to the even digit.
- Allocation: splitting an amount without losing remainders.