Template:Formatnum/1
From Meta, a Wikimedia project coordination wiki
This template is the core template of Template:Formatnum. That template handles the empty string and invalid numbers, and the possible minus sign, so that this template needs to handle valid non-negative numbers only. Also Formatnum applies rounding according to parameter prec, if defined, and increases the absolute value so that this template can truncate after a total of 16 digits, and supplies this template with the log to the base 10, rounded down, of this final number.
Contents |
[edit] Parameters
| Parameter name | Description | Default value |
|---|---|---|
| 1 | non-negative number | 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 |
| oom | log to the base 10, rounded down, of the number. | empty |
Examples
Some results depend on the user language, try: de • en • fr • nl
{{formatnum|1234567890.456789789}}→ 1,234,567,890.45679- 1,234,567,890.45679
{{#expr:(abs(.456789789)+5*10^(-16+9))}}→ 0.456790289
{{formatnum|9999999999.99999}}→ 9,999,999,999.99999{{formatnum/1|(9999999999.99999+5*10^(-16+9))|oom=9}}→ 9,999,999,999.99999{{#expr:(abs(.99999)+5*10^(-16+9))}}→ 0.9999905{{oom|10000000000}}→ 10
{{formatnum|9999999999.999999}}→ 9,999,999,999.999998{{formatnum/1|(9999999999.999999+5*10^(-16+9))|oom=9}}→ 9,999,999,999.999998{{#expr:(abs(.999999)+5*10^(-16+9))}}→ 0.9999995{{oom|(abs(9999999999.999999)+5*10^(-16+9))}}→ 9
Compare:
-
{{oom|{{#expr:(abs(9999999999.999999)+5*10^(-16+9))}}}}→ 10{{formatnum/1|(9999999999.999999+5*10^(-16+9))|oom=10}}→ 9,999,999,999.99999
{{formatnum|9999999999.9999999}}→ 10,000,000,000{{formatnum/1|(9999999999.9999999+5*10^(-16+9))|oom=10}}→ 10,000,000,000{{#expr:(abs(.9999999)+5*10^(-16+9))}}→ 1.0000004{{oom|(abs(9999999999.9999999)+5*10^(-16+9))}}→ 10
{{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.120000001{{formatnum|567890.12}}→ 567,890.12{{formatnum|67890.12}}→ 67,890.12{{formatnum|7890.12}}→ 7,890.120000000001{{formatnum|890.12}}→ 890.12{{formatnum|90.12}}→ 90.12{{formatnum|4.12}}→ 4.12000000000000{{formatnum|4.1}}→ 4.1{{formatnum|4}}→ 4.00000000000000
{{formatnum|1234567890.12345}}→ 1,234,567,890.12345{{formatnum|1234567890.123456}}→ 1,234,567,890.123456
{{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}}→ 9,999,999,999.99999{{formatnum|9999999999.999999}}→ 9,999,999,999.999998{{formatnum|9999999999.9999999}}→ 10,000,000,000
{{formatnum|-6.7e-8}}→ -0.000000067{{formatnum|0}}→ 0{{formatnum|0|bn}}→ ০{{formatnum|6.7e-18}}→ 0.00000000000000{{formatnum|6.7e-8}}→ 0.000000067{{formatnum|6.7e8}}→ 670,000,000{{formatnum|1.234567890123456e17}}→ 123,456,789,012,345,648{{formatnum|6.7e17}}→ 670,000,000,000,000,000{{formatnum|1.234567890123456e18}}→ 234,567,890,123,456,682{{formatnum|6.7e18}}→ 700,000,000,000,000,000
{{formatnum|e8}}→ e8 (not a valid number, returns the input){{formatnum}}→
Required
Localization
This template does not have to be localized itself.
| The above documentation is transcluded from Template:Formatnum/1/doc. (edit | history) Editors can experiment in this template's sandbox (create) and testcases (create) pages. Please add categories and interwikis to the /doc subpage. Subpages of this template. |