Solved

How can I add four decimals to invoice numbers?

King-Kang
Trailblazer
148 8 76

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

Accepted Solution (1)

Wehateonions
Shopify Partner
25 4 18

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 }}
In need of a Shopify developer for a bespoke app or theme, or maybe just someone that can help you out. Give us a shout, we are always happy to help. Wehateonions

View solution in original post

Replies 6 (6)

diego_ezfy
Shopify Partner
2967 571 899

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

Wehateonions
Shopify Partner
25 4 18

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 }}
In need of a Shopify developer for a bespoke app or theme, or maybe just someone that can help you out. Give us a shout, we are always happy to help. Wehateonions
devilperfume
Visitor
2 0 0

Hi,

can I add this code to a specific product or must I add this to the base?

Thanks

wesstraub
Tourist
4 0 3

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?

pinerefillery
Visitor
1 0 0

I would also love to know how to implement this solution. Have you figured out where to implement this? 

King-Kang
Trailblazer
148 8 76

@diego_ezfy  @Wehateonions 

Thank you guys 🙂 I managed with the split and size