# Template:Decimals

Jump to navigation Jump to search Template documentation[view]  [history] [purge]

## Usage

`{{Decimals|number|decimals}}`

The given number may be an expression that could be evaluated using `{{#expr:number}}`. If number is invalid, an error message is displayed.

Using `{{Decimals|number|decimals|error=text}}` displays number if valid, or text otherwise; in this case, there is no error message.

Results are supposed to be limited to 15 significant figures, but there is currently a bug in the implementation that makes the rounding of the 14th and 15th significant figures incorrect, so only 13 significant figures can be trusted to be correct. Therefore, inputs that can result in outputs of more than 13 significant figures should be avoided. This can also happen when a large number is displayed even with only a few decimals; for instance, 1234567890123.456789 with 2 decimals will be displayed as 1234567890123.50, with both decimals being incorrect. The relative error is of course extremely small, but nevertheless the displayed number will be incorrect.

## Examples

### Well-functioning examples, normal use

• `{{Decimals|1234|-4}}` → 0 (rounds to nearest 10,000)
• `{{Decimals|1234|-2}}` → 1200 (rounds to nearest 100)
• `{{Decimals|1234|0}}` → 1234
• `{{Decimals|1234|1}}` → 1234.0
• `{{Decimals|1234|2}}` → 1234.00
• `{{Decimals|9/8|5}}` → 1.12500
• `{{Decimals|1/33|7}}` → 0.0303030
• `{{Decimals|0.006|1}}` → 0.0
• `{{Decimals|2x345|2}}`Lua error: Expression error: Unrecognized word "x"..
• `{{Decimals|2x345|2|error=–}}` → – (custom error message)

### Extreme examples, exposing problems

These examples are extremes, requesting for more than 13 decimals. These situations will rarely if ever be in actual use, but they do expose one or more actual bugs.

• `{{Decimals|0.00000123456789012345|20}}` → 0.00000123456789012340 (20 decimals, 15th significant figure wrongly converted from 5 to 0, perhaps because the number was limited to 14 significant figures, where the 14th figure wasn't even rounded correctly)
• `{{Decimals|0.0000012345678901234567890|20}}` → 0.00000123456789012350 (20 decimals, 14th and 15th significant figure wrongly displayed as 50 instead of 46, perhaps because the number was limited to 14 significant figures and a 0 just appended?)
• `{{Decimals|0.0000067890123456789012345|20}}` → 0.00000678901234567890 (20 decimals, touching the limit of 15 significant figures, but perhaps obscuring that only 14 significant figures are in fact used)
• `{{Decimals|0.12345678901234567890|20}}` → 0.123456789012350 (seemingly limited to 14 significant figures, but still appending a weird 0)
• `{{Decimals|0.67890123456789012345|20}}` → 0.678901234567890 (seemingly limited to 15 significant figures, but perhaps obscuring that only 14 significant figures are in fact used and a 0 then appended)
• `{{Decimals|67890.123456789012345|20}}` → 67890.1234567890 (seemingly limited to 15 significant figures, but perhaps obscuring that only 14 significant figures are in fact used and a 0 then appended)
• `{{Decimals|12345678901234567890|20}}` → 1.2345678901235e+19 (limited to 14 significant figures)
• `{{Decimals|67890123456789012345|20}}` → 6.7890123456789e+19 (limited to 14 significant figures)
• `{{Decimals|1234567890123.456789|2}}` → 1234567890123.50 (seemingly limited to 15 significant figures, but likely obscuring that only 14 significant figures are in fact used and a 0 then appended, resulting in both decimals being incorrect)

## TemplateData

Rounds a given number to a given number of decimals. Note that results are limited to 15 significant figures.

Template parameters

ParameterDescriptionTypeStatus
Number`1`

The number to be rounded.

Stringrequired
Decimals`2`

The number of decimals. Use negative numbers to round tens, hundreds, thousands etc. (Example: 1257 with -2 decimals gives 1300)

Example
2
Numberrequired