Liquid HTML - Format to 2 decimals

We are using {{value|round:2}} to round decimal points, but we need to add 0s to transform values like “3.0” to “3.00”.

In BigQuery, we can use FORMAT("%.2f", price) which does what we want. Is there a liquid html function that does this? We’d rather use liquid html than having to add that function to all of our dimensions’ sql statements or use the dashboard visualization formatting in the series section.

Solved Solved
0 2 7,410
1 ACCEPTED SOLUTION

Why don’t you use paramater:

value_format_name: decimal_2

If there is a reason for using Liquid I found this: https://stackoverflow.com/questions/37862167/trailing-zeros-in-jekyll-liquid

{% assign price_split = page.products[0].price | round: 2 | split: "." %}
{% assign integral = price_split[0] %}
{% assign fractional = price_split[1] | append: "00" | truncate: 2, "" %}

Formatted Price: {{ integral }}.{{ fractional }}

View solution in original post

2 REPLIES 2

Why don’t you use paramater:

value_format_name: decimal_2

If there is a reason for using Liquid I found this: https://stackoverflow.com/questions/37862167/trailing-zeros-in-jekyll-liquid

{% assign price_split = page.products[0].price | round: 2 | split: "." %}
{% assign integral = price_split[0] %}
{% assign fractional = price_split[1] | append: "00" | truncate: 2, "" %}

Formatted Price: {{ integral }}.{{ fractional }}

Unfortunately, nearly every dimension/measure in our system uses html for other customization purposes, so while we do have v`alue_format_name` in place for when reports are downloaded, it doesn’t help us within actual dashboards/looks.

Thank you for linking that liquid code. I was able to implement that; it worked perfectly!

Top Labels in this Space
Top Solution Authors