Extension:NumberFormat
Appearance
NumberFormat Release status: stable |
|
---|---|
Implementation | Parser function |
Description | Allows to format numbers by inserting thousands separators or rounding to a given number of decimals |
Author(s) | |
Maintainer(s) | Pavel Astakhov |
Latest version | 0.9.0 (2017-07-19) |
MediaWiki | 1.23+ |
PHP | 5.3+ |
Database changes | No |
License | GNU Lesser General Public License 3.0 or later |
Download | |
Example | test.foxway.org |
Quarterly downloads | 7 (Ranked 126th) |
Translate the NumberFormat extension if it is available at translatewiki.net | |
The NumberFormat extension allows to format numbers by grouping thousands and/or specifying the number of decimals to be shown. Additionally the number will be rounded if necessary. The symbols used as thousands separator and decimal point can optionally be specified.
This extension is most useful in conjunction with other extensions that print "raw" numbers — for example Semantic MediaWiki (see this tip on how to use NumberFormat with Semantic MediaWiki).
NumberFormat is a simple wrapper for the number_format()
PHP function and uses the same default values.
Installation
[edit]- Download and move the extracted
NumberFormat
folder to yourextensions/
directory.
Developers and code contributors should install the extension from Git instead, using:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/NumberFormat - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'NumberFormat' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Usage
[edit]{{#number_format: number | decimals | dec_point | thousands_sep | orig_dec_point }}
where:
- number - the number being formatted (default empty)
- decimals - sets the number of decimal points (default "0", set "_" for do not round)
- dec_point - sets the separator for the decimal point (default ".")
- thousands_sep - sets the thousands separator (default ",", "n" = " " and "t" = " ")
- orig_dec_point - sets the separator for the decimal point in original number (default not set, if set - extension replace it to "." before use)
Example | Result | Explanation |
---|---|---|
{{#number_format:12345678.055555}}
|
12,345,678 | Default behaviour: Round to whole number, insert ',' thousands separators |
{{#number_format:12345678.055555|2}}
|
12,345,678.06 | Round to two decimal places (useful for monetary amounts) |
{{#number_format:12345678.055555|2|,|.}}
|
12.345.678,06 | Round to two decimal places, use '.' as thousands separators and ',' as decimal point |
{{#number_format:12345678.055555|2|,|_}}
|
12 345 678,06 | Round to two decimal places, use a space as thousands separators and ',' as decimal point |
{{#number_format:1.2345678055555e7|4}}
|
12,345,678.0556 | Scientific notation is also accepted - here rounded to four decimal places |
{{#number_format:12,345,678.055555}}
|
12,345,678 | |
{{#number_format:12345678.055555|_|,|n}}
|
12 345 678,055555 | No Round, use a non-break-space ( ) as thousands separators and ',' as decimal point |
{{#number_format:12 345 678,055555|_|.||,}}
|
12345678.055555 | Convert French user input to plain number (for example, use the user entered a number in parser function #expr.) |
See also
[edit]- Help:Magic words#Formatting for the built-in formatting capabilities of MediaWiki using Magic words.
- Extension:PhpTags Functions/Functions/String, includes
number_format
,money_format
and more than seventy functions for working with strings using the PHP syntax.
This extension is included in the following wiki farms/hosts and/or packages: This is not an authoritative list. Some wiki farms/hosts and/or packages may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |