Money & currency¶
A money value is an amount plus a currency. money() formats the pair using the
locale's symbol, placement, grouping, and — crucially — the currency's own minor
units: most currencies show two fraction digits, JPY shows none, and a few (e.g.
BHD) show three. Cosmo only formats a value; it never converts between currencies.
For plain numbers, percentages, and units, see Numbers.
Formatting an amount¶
The currency is resolved in this order: an explicit code passed to money(),
then the currency modifier set on the instance, then (where supported) the
locale region. The symbol is the locale's disambiguated form — en_US writes
Australian dollars as A$, not the ambiguous $. Amounts are rounded to the
currency's minor units (halfExpand by default), and the rounding/grouping
options bag applies here too.
Region → currency inference differs
PHP, Python, and Java infer the currency from the locale's region when you
omit a code (Cosmo("en_AU").money(100) → $100.00). JavaScript does not —
its Intl-only design forbids a region→currency mapping, so money() returns
"" unless you pass a code or set the currency modifier. This is a capability
difference, not an error; see Platform notes.
Currency names & symbols¶
To display a currency on its own — its localised name or symbol, with no
amount attached — use currency():
currency() is part of the wider locale metadata
family (alongside language(), country(), and friends) — that page covers it in
full, including the strict-symbol behaviour.