Template:Formatnum

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Template documentation[view] [edit] [history] [purge]

This template formats a number in the local format (local numerals, local thousands separator, decimal separator and the pattern of separators) of a given language.

The total number of digits before and after the decimal point is limited to 16. In the 16th digit there may be a deviation of 1 or 2 units, as the unit in the last place (ulp) has a maximum of 2.22 units in the 16th digit (see also Help:Calculation#Accuracy).

Parameters[edit]

Parameter name Description Default value

1 number without thousands separators empty
2 language code value of {{int:Lang}}
sep set to any non-empty value to produce a result without thousands separators empty
prec number of digits after the decimal point to show if empty or undefined: 0

Examples

Some results depend on the user language, try: deenfrnl

  • {{formatnum|1234567890.123}} → 1,234,567,890.123
  • {{formatnum|-1234567890.123}} → -1,234,567,890.123
  • {{formatnum|1234567890.123|en}} → 1,234,567,890.123
  • {{formatnum|1234567890.123|sep=x}} → 1234567890.123
  • {{formatnum|1234567890.123|en|sep=x}} → 1234567890.123
  • {{formatnum|1234567890.123|nl}} → 1.234.567.890,123
  • {{formatnum|1234567890.123|de}} → 1.234.567.890,123
  • {{formatnum|1234567890.123|fr}} → 1 234 567 890,123
  • {{formatnum|1234567890.123|bn}} → ১,২৩,৪৫,৬৭,৮৯০.১২৩ (Bengali)
  • {{formatnum|1234567890.123|hi}} → १,२३,४५,६७,८९०.१२३ (Hindi)
  • {{formatnum|1234567890.123|fa}} → ۱٬۲۳۴٬۵۶۷٬۸۹۰٫۱۲۳ (Persian)
  • {{formatnum|1234567890.123|kn}} → ೧,೨೩,೪೫,೬೭,೮೯೦.೧೨೩ (Kannada)
  • {{formatnum|1234567890.123|pa}} → 1,23,45,67,890.123 (Punjabi)
  • {{formatnum|123456789012.12}} → 123,456,789,012.12
  • {{formatnum|12345678901.12}} → 12,345,678,901.12
  • {{formatnum|1234567890.12}} → 1,234,567,890.12
  • {{formatnum|234567890.12}} → 234,567,890.12
  • {{formatnum|34567890.12}} → 34,567,890.12
  • {{formatnum|4567890.12}} → 4,567,890.12
  • {{formatnum|567890.12}} → 567,890.12
  • {{formatnum|67890.12}} → 67,890.12
  • {{formatnum|7890.12}} → 7,890.12
  • {{formatnum|890.12}} → 890.12
  • {{formatnum|90.12}} → 90.12
  • {{formatnum|4.12}} → 4.12
  • {{formatnum|4.1}} → 4.1
  • {{formatnum|4}} → 4
  • {{formatnum|1234567890.12345}} → 1,234,567,890.1235
  • {{formatnum|1234567890.123456}} → 1,234,567,890.1235
  • {{formatnum|1234567890|prec=3}} → 1,234,567,890.000
  • {{formatnum|1234567890.1|prec=3}} → 1,234,567,890.100
  • {{formatnum|1234567890.12|prec=3}} → 1,234,567,890.120
  • {{formatnum|1234567890.123|prec=3}} → 1,234,567,890.123
  • {{formatnum|1234567890.1234|prec=3}} → 1,234,567,890.123
  • {{formatnum|1234567890.12345|prec=3}} → 1,234,567,890.123
  • {{formatnum|1234567890.123456|prec=3}} → 1,234,567,890.123
  • {{formatnum|0.000123456|prec=3}} → 0.000
  • {{formatnum|9999999999.9999}} → 9,999,999,999.9999
  • {{formatnum|9999999999.99999}} → 10,000,000,000
  • {{formatnum|9999999999.999999}} → 10,000,000,000
  • {{formatnum|9999999999.9999999}} → 10,000,000,000
  • {{formatnum|-6.7e-8}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|0}} → 0
  • {{formatnum|0|bn}} → ০
  • {{formatnum|6.7e-18}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|6.7e-8}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|6.7e8}} → 670,000,000
  • {{formatnum|1.234567890123456e17}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|6.7e17}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|1.234567890123456e18}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|6.7e18}}Lua error: bad argument #2 to 'gsub' (string expected, got nil).
  • {{formatnum|e8}} → e8 (not a valid number, returns the input)
  • {{formatnum}}

Required

Localization

This template does not have to be localized itself.

See also