**Congressional Millionaire’s Club**

The Personal Gain Index shines a light on how members of Congress benefit during their tenure.

# Help:Format Number

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:

{{formatnum:547859.286}} ^{[1]}

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

547,859.286

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:

547859.286

## 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:

515,223

Proper use in a parser"

{{#expr:{{formatnum:{{NUMBEROFPAGES}}|R}} + 500}}

Renders:

515723

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:

{{formatnum:{{#expr:58729+65735}}}}

124,464

To format and restrict decimals:

{{formatnum:{{#expr:58729.5678+65735.8567 round2 }}}}

124,465.42

## References

- ↑
^{1.0}^{1.1}MediaWiki Extension:Parser Functions

## Frequently asked questions

Question: Why does my page look like this?Expression error: Unrecognized punctuation character ",". |
---|

Response: 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. |