Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi, I am currently trying to add four decimals (0,0000) to the numbers in my invoice.
I managed a way when the numbers are not zeros (example: 1,52 to 1,5246), multiplying the number by 100 and divide it by 100.
But I also need to show it when the other numbers are zeros (example: 1,2 to 1,2000).
Can somebody help me?
Thank you
Solved! Go to the solution
This is an accepted solution.
Hi, I would use this method to achieve adding the trailing 0s. This will append a 0 up to 4 decimal places regardless of the rounding length.
For example you could have a price of 1.76 and it would display as 1.7600, or you could have a number of 1.7666 which would display as true 1.7666. You can adjust the round and truncate length if you want more or less 0s to trail. Hope this helps.
{% assign price = 1.765 %}
{% assign price_split = price | round: 4 | split: "." %}
{% assign int = price_split[0] %}
{% assign frac = price_split[1] | append: "0000" | truncate: 4, "" %}
Formatted: {{ int }}.{{ frac }}
Hello,
I confess this is a very non-elegant solution, but here is an idea:
{% assign price = 20.3 %}
{% assign price_aux = price | split: '.' %}
{% assign digits_before_dot = price_aux[0] | size %}
{% assign price = price | times: 10000 | downcase %}
{% assign price_size = price | size %}
<div>
<small>original: {{price}}</small> <!-- output: original: 203000.0 -->
<p>formatted: {{price | slice: 0,digits_before_dot }}.{{price | replace: '.', '' | slice: digits_before_dot, price_size }}</p> <!-- output: original: 20.30000 -->
</div>
It should also be able to detect commas not only dots, but I believe this can be a starting point.
Let me know your thoughts!
Note: I just noticed I made it with 5 decimals but it's easily editable!
Regards,
Diego
This is an accepted solution.
Hi, I would use this method to achieve adding the trailing 0s. This will append a 0 up to 4 decimal places regardless of the rounding length.
For example you could have a price of 1.76 and it would display as 1.7600, or you could have a number of 1.7666 which would display as true 1.7666. You can adjust the round and truncate length if you want more or less 0s to trail. Hope this helps.
{% assign price = 1.765 %}
{% assign price_split = price | round: 4 | split: "." %}
{% assign int = price_split[0] %}
{% assign frac = price_split[1] | append: "0000" | truncate: 4, "" %}
Formatted: {{ int }}.{{ frac }}
Hi,
can I add this code to a specific product or must I add this to the base?
Thanks
Hi there, I am looking for this very solution (adding 3-4 decimal places to all prices, instead of Shopify rounding them to two places). How / where do I implement this?
I would also love to know how to implement this solution. Have you figured out where to implement this?
Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025