Formatting numbers
PDFMonkey provides two filters that help with formatting numbers: with_delimiter and format.
This filter is great for formatting money!
In most cases the last one should be enough as is gives a way to specify the decimal delimiter, the thousands separator and the precision (number of digits after the decimal delimiter).
For more rare and advanced cases, you may need format as it provides ways to pad numbers, conditionally include decimals, etc.
This filter is based on the Ruby format method. You can learn more about all the possibilities in the dedicated documentation.
with_delimiter
This filter is great for formatting money!
{{12345.67 | with_delimiter, delimiter: ' ', separator: ',' }}€
12 345,67€
£{{12345 | with_delimiter, precision: 2}}
£12,345.00
In most cases the last one should be enough as is gives a way to specify the decimal delimiter, the thousands separator and the precision (number of digits after the decimal delimiter).
{{12345678 | with_delimiter}}
12,345,678
{{'123456' | with_delimiter}}
123,456
{{12345678.05 | with_delimiter}}
12,345,678.05
{{12345678 | with_delimiter, delimiter: '.'}}
12.345.678
{{12345678 | with_delimiter, delimiter: ','}}
12,345,678
{{12345678 | with_delimiter, delimiter: ',', precision: 2}}
12,345,678.00
{{12345678.05 | with_delimiter, separator: ' '}}
12,345,678 05
{{12345678.05 | with_delimiter, delimiter: ' ', separator: ','}}
12 345 678,05
{{'123a' | with_delimiter}}
123a
format
For more rare and advanced cases, you may need format as it provides ways to pad numbers, conditionally include decimals, etc.
{{5 | format: "%05d"}}
00005
{{5 | format: "%08.3f"}}
0005.000
{{5 | format: "%.2f"}}
5.00
{{5.1234 | format: "%.2f"}}
5.12
This filter is based on the Ruby format method. You can learn more about all the possibilities in the dedicated documentation.
Updated on: 30/05/2023
Thank you!