Liquid Filter Reference for number - v0.9.5
Filter Name | number |
Group | Numbers |
Version | 0.9.5 |
Description
Formats the input as a number according to the locale
Examples
When there are no decimals, it formats the number with no decimals:
{{ 12 | number }}
12
When the number already has the default number of decimal places per the locale, it leaves the number as is:
{{ 12.768 | number }}
12.768
When there are more than the default number of decimal places per the locale, it rounds the number to the default number of decimal places per the locale:
{{ 12.7689 | number }}
12.769
Options
compact
Removes insignificant zeros after the decimal separator. Default: “true” unless precision
is specified.
When there are no decimals, it formats the number with no decimals:
{{ 12 | number, compact: true }}
12
When there are no insignificant zeros, it keeps all the decimals:
{{ 12.76 | number, compact: true }}
12.76
When there is an insignificant zero, it removes the zero:
{{ 12.70 | number, compact: true }}
12.7
When there are all insignificant zeros, it removes all the zeros:
{{ 99.00 | number, compact: true }}
99
When false, it does not remove any zeros:
{{ 99.100 | number, compact: false }}
99.100
When precision
is used, it defaults to false and does not remove any zeros:
{{ 99.10000 | number, precision: 4 }}
99.1000
When true and used with precision
, it removes the zeros:
{{ 99.1010 | number, precision: 6, compact: true }}
99.101
delimiter
Sets the thousands delimiter. Default: “”
When when a comma is specified, it uses the comma as the delimiter:
{{ 12000 | number, delimiter: "," }}
12,000
separator
Sets the separator between the fractional and integer digits (defaults to “.”)
When when a comma is specified, it uses the comma as the separator:
{{ 12.76 | number, separator: "," }}
12,76
precision
Defines the number of decimal places
When there are no decimals, it formats to the supplied number of decimal places:
{{ 12 | number, precision: 3 }}
12.000
When the number already has the supplied number of decimal places, it leaves the number as is:
{{ 12.763 | number, precision: 3 }}
12.763
When there are more than the supplied number of decimal places, it rounds the number to the supplied number of decimal places:
{{ 12.7682 | number, precision: 3 }}
12.768
Back to Liquid Reference for 0.9.5
Back to Documentation