0
votes

I am trying to find a solution for the following problem. I have a list of lenses with different powers. They are starting from -12.00 and going up to +8.00. For the most part, they are 0.50 apart from the next one (6.00, 6.50, 7.00 s.o.).
I have a list with all the possible powers stored under settings, in an array. And then for each available brand of lenses it has a metafield with the minimum available power and the maximum one.
I envisioned it as a comparison, display only the powers from settings that are between these limits. However, I hit a limitation. I can't store 6.5 for example in a metafield as a number, it can only be a string and it makes it hard to compare the settings value with this one.
I tried to use a math filter (times), but the number is rounded. If I have "6.5" and I use times filter, I get "6".

Questions:
1. How would you do this?
2. How can I make sure that each value, if it is not a string, have two decimal places? (e.g. 6.50)

1
Hi Andrew, I would like to talk to you about something VERY important. Can you send an email to me at sachinkainth[at]hotmail.com please? Thanks.Sachin Kainth

1 Answers

1
votes

Let's say the metafield is like this product.metafields.power.value = 6.5. Do this:

{% assign power_value = product.metafields.power.value | plus: 0 %}

Boom. power_value is now a number.