Extension:FormatNum

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

Release status: stable

Implementation Parser function
Description Passes number formating instruction to PHP function number_format
Author(s) DaSch
Last version 0.2.0 (2010-02-16)
License Public Domain
Download Download snapshot
Subversion [Help]

Browse source code
View code changes

Hooks used
ParserFirstCallInit

LanguageGetMagic

Check usage (experimental)

Extension FormatNum makes it easier to format numbers in the style you want, independent of language settings.

Usage

{{#formatnum:number|number of decimals|decimal separator|thousand separator}}

Example
{{#formatnum: 2300.123|2|,|_}}
result: 2 300,12
{{#formatnum: 2300.123|2|.|,}}
result: 2,300.12
{{#formatnum: 2300.123|2}}
result: 2,300.12
{{#formatnum: 2300.123|2|,|t}}
result: 2 300,12

As thousand separator there can be also used the following parameters

  • n – will be  
  • t – will be  

[edit] Installation

Download the files from SVN. But them in /extensions/FormatNum and but the following to your LocalSettings.php

require_once( "$IP/extensions/FormatNum/FormatNum.php" );

[edit] Use Example

On Wikipedia formatting of numbers is done with complex templates like this. With the #formatnum parser this would be a lot easier.

[edit] See also

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox