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
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 %}
<small>original: {{price}}</small>
formatted: {{price | slice: 0,digits_before_dot }}.{{price | replace: '.', '' | slice: digits_before_dot, price_size }}
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
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 }}
@diego_ezfy @Wehateonions
Thank you guys
I managed with the split and size
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?