How can I set a variable to 3 decimals in Dawn 5?

Solved

How can I set a variable to 3 decimals in Dawn 5?

Sneaky
Shopify Partner
32 3 20

I am trying to figure out how I can set a variable in my theme.liquid file to 3 decimals, it currently reverts to 2 decimals.  So for example I may have a result calculation that should be 1.875 but it rounds to 1.87

 

I have tried to divide by a 3 decimal number, e.g. 100.000, or 1.000, or 2.000 etc

I have tried to set round to 3

I have tried to set abs

 

Nothing is working so far, it always reverts to 2 decimals.

 

Any suggestions?

Accepted Solution (1)

Sneaky
Shopify Partner
32 3 20

This is an accepted solution.

OK, I am not sure why but I was able to fix it by switching the order of my divide_by in the calculation.

Example

 

{{ settings.font_number_size | times: settings.font_default_scale | divided_by: settings.font_body_size | divided_by: 100.000 | round: 3 }}

 

 

To

 

{{ settings.font_number_size | times: settings.font_default_scale | divided_by: 100.000 | divided_by: settings.font_body_size | round: 3 }}

 

Well, it resolves my specific issue

 

I looked at this again and to be easier just adding a times or divide_by as 1.000 fixes it too.

For example

 

{{ settings.font_number_size | times: settings.font_default_scale| times: 1.000 | divided_by: settings.font_body_size | divided_by: 100 | round: 3 }}

 

View solution in original post

Replies 6 (6)

Sneaky
Shopify Partner
32 3 20

This is an accepted solution.

OK, I am not sure why but I was able to fix it by switching the order of my divide_by in the calculation.

Example

 

{{ settings.font_number_size | times: settings.font_default_scale | divided_by: settings.font_body_size | divided_by: 100.000 | round: 3 }}

 

 

To

 

{{ settings.font_number_size | times: settings.font_default_scale | divided_by: 100.000 | divided_by: settings.font_body_size | round: 3 }}

 

Well, it resolves my specific issue

 

I looked at this again and to be easier just adding a times or divide_by as 1.000 fixes it too.

For example

 

{{ settings.font_number_size | times: settings.font_default_scale| times: 1.000 | divided_by: settings.font_body_size | divided_by: 100 | round: 3 }}

 

afcompany
Shopify Partner
16 0 9

Where do you make this change? I am trying to get my cart to display .000 or .0000 (3 or 4) decimal places.

wesstraub
Tourist
4 0 3

Where / what file are you making this modification to?

qrsupplyhouse
Visitor
1 0 0

Where is this code to be inputted?

afcompany
Shopify Partner
16 0 9

So, I was able to output this anywhere we were outputting price. The problem, is that regardless of us displaying the extra decimals, the Shopify cart WILL ALWAY round back with only the 2 decimal places. This caused more problems for accounting, so we had to move away from showing this value. Pretty frustrating when were were working on discounting with percents. We should the customer what percent discount they were getting, but in the end, Shopify always rounded up and the customer never got the full discount.

hb-manuel
Tourist
7 0 0

Hi @afcompany , I could not find this code in my theme.liquid, where did you make the changes?