Numbers¶
Format decimals, percentages, units, scientific and compact notation, and spelled-out or ordinal forms — all in the locale's conventions, straight from ICU. For currency amounts, see Money & currency.
Every numeric method shapes its output for the instance locale: the grouping and
decimal separators, the digit set (Western 0-9, Arabic-Indic ٠-٩, Devanagari
०-९, …), and the sign and percent placement all come from CLDR. You never format
digits by hand.
Decimals, percentages & units¶
number()formats a plain decimal in the locale's style — note howdeswaps the roles of.and,.percentage()takes a fraction, not a pre-multiplied percent:0.2→20%. An optional second argument sets the precision.unit()pairs a measurement type and unit with a value and an optional width (none·short·medium·long·full) —shortgives26°C, the defaultlonggives2.19 gigabytes. The type/unit names are the CLDR identifiers (digital/gigabyte,temperature/celsius,length/meter, …).
Rounding & grouping options
number(), percentage(), and money() accept an options bag with
the portable keys minimumFractionDigits, maximumFractionDigits,
minimum/maximumSignificantDigits, roundingMode, roundingIncrement, and
useGrouping — identical in all four ports, with a halfExpand rounding
default. (Java passes a Map<String, Object> with the same camelCase keys.)
The keys stay camelCase even in Python so the same config travels between
languages unchanged — see Terminology.
Scientific & compact notation¶
compact() shortens large magnitudes — short (default) gives the symbol form
(1.2K), long spells the scale word (1.2 thousand), both localised.
scientific() renders exponential notation.
compact() works everywhere now
Compact notation (1.2K, 1.2 thousand) is available in all four ports.
PHP reaches it through an ICU compact-notation style its ext-intl binding
accepts even though it isn't exposed as a named constant; the others use the
modern ICU NumberFormatter. scientific() is likewise universal.
Spelled-out & ordinal numbers¶
spellout() writes a number out in words; ordinal() gives the ordinal text
(1st, 2nd, 3rd). symbol() returns a single locale notation symbol by name
(decimal, group, percent, …) — handy when you render numbers in a custom
template.
spellout() / ordinal() are PHP, Python & Java
Spelling numbers out and ordinal text ("1st", "2nd") come from ICU's
rule-based number formatter (RBNF), which the JavaScript Intl API does not
expose — so these three tabs omit JS. For the ordinal plural category (which
JS does have), see Messages & plurals. symbol()
likewise accepts a wider set of names in PHP/Python/Java than JS exposes.