Elections will be held in New Hampshire and Washington, D.C., today. Find out what's on your ballot!

Help:Format Number

From Ballotpedia
Jump to: navigation, search

The Format Number extension and parser allows you to format a number in different ways at any point on the wiki. Basically, the function allows you to add or remove commas from a manually entered number. For more advanced formatting like adjust decimals and rounding, you will need to use this function in combination with Expression parsers

Function format

There are two key functions of the formatnum parser. The first adds commas to a raw number to make it more readable. The code looks like:


This will take an unformatted number and apply the default formatting. It looks like this:


The other function removes formatting from an already formatted number. This can be useful when dealing with Fixed variables that are needed in equations.

{{formatnum: 547,859.286|R}}[1]

Will render:


Advanced formatting in combination with expressions

Using fixed variables in an expression

Fixed variables inevitably render as formatted numbers on the wiki. However, this formatting precludes you from using them in their natural form in an equation. To avoid this, use the formatnum parser to incorporate them into the parser.

Fixed Variable:

Proper use in a parser"
{{#expr:{{formatnum:{{NUMBEROFPAGES}}|R}} + 500}}


Improper use renders:
Expression error: Unrecognized punctuation character ",".

Formatting in combination with expressions

As displayed above you may want to use the formatnum function to properly format a number to be used in an expression. You may also want format the finished product of a function by adding commas to the number. Additional formatting can be done using the expression function.

To format an expression number:

To format and restrict decimals:
{{formatnum:{{#expr:58729.5678+65735.8567 round2 }}}}


Frequently asked questions

Question:  Why does my page look like this?
Expression error: Unrecognized punctuation character ",".
This is a result of improper number formatting. Many fixed variables carry commas in their autmoatic formatting. Look at your code and use {{formatnum:NUMBER}} to eliminate any commas automatically.