decimal

Formats a number with the given number of decimal places, rounding to the nearest value at that precision.

InputArgumentsReturnsanyintstringanyno argumentsstring
Source
BasicSource

Formats a number with the given number of decimal places, rounding to the nearest value at that precision.

Given

{"ratio": 1.23456}

Template

{{ ratio | decimal:4 }}

Result

1.2346
ZeroSource

Rounds to a whole number when zero decimal places are requested.

Given

{"n": 42.7}

Template

{{ n | decimal:0 }}

Result

43
BasicSource

Formats a number with two decimal places, the clause reached when no precision is given.

Given

{"price": 3.5}

Template

{{ price | decimal }}

Result

3.50
StringSource

Parses a numeric string before formatting it, so a value that arrives as text still renders with two decimal places.

Given

{"amount": "7.5"}

Template

{{ amount | decimal }}

Result

7.50