From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png

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) Patrick Nagel, Pavel Astakhov
Latest version 0.8.0 (2014-06-16)
MediaWiki 1.19+
PHP 5.3+
Database changes No
License GNU Lesser General Public License
Download Template:WikimediaDownload/gerritonly
Example test.foxway.org
Hooks used

Translate the NumberFormat extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

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.

Usage[edit | edit source]

{{#number_format: number | decimals | dec_point | thousands_sep | orig_dec_point }}


  1. number - the number being formatted (default empty)
  2. decimals - sets the number of decimal points (default "0", set "_" for do not round)
  3. dec_point - sets the separator for the decimal point (default ".")
  4. thousands_sep - sets the thousands separator (default ",", "n" = " " and "t" = " ")
  5. orig_dec_point - sets the separator for the decimal point in original number (default not set, if set - extension replace it to "." before use)

Wiki text Result ver 0.4.1 Result ver 0.6.0 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}} First argument to number_format must be a number 12,345,678 The original number must be a plain number, without thousands separators etc.
{{#number_format:12345678.055555|_|,|n}} n/a 12 345 678,055555 No Round, use a non-break-space ( ) as thousands separators and ',' as decimal point
{{#number_format:12 345 678,055555|_|.||,}} n/a 12345678.055555 Convert French user input to plain number (for example, use the user entered a number in parser function #expr.)

Installation[edit | edit source]

vagrant>Vagrant</>, install with <tvar

  • <translate>

1>download-link</> and place the file(s) in a directory called <tvar|name>NumberFormat</> in your <tvar|ext>extensions/</> folder.</translate>

  • <translate>

Add the following code at the bottom of your LocalSettings.php:</translate>

require_once "$IP/extensions/NumberFormat/NumberFormat.php";
  • YesY Done <translate>

Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.</translate>

See also[edit | edit source]