When creating a ‘Number’ metafield, is it possible to define the number of decimal places to be displayed? I need to add the cost per kg of a product (i.e. £x.xx) to display below the price on a product page, so I need it to display to 2 decimal places. Is this possible?
Hi @martincoard ,
I don’t really understand the question, but if you want to add decimal you just select ‘decimal’ it will work fine.
Or if you want to set condition for it, you can refer to this: https://shopify.dev/api/liquid/filters/math-filters#round
Hope it helps!
Thank you for your reply.
What had foxed me was that the Decimal option offers control of the minimum and maximum values and maximum precision, but if you want to use it to hold a monetary value you always want it to display to 2 decimal places. I’ve found that if you want to display £4.50 for example (with the £ sign coming from the separate prefix text) it will display 4.5 but not 4.50.
It isn’t really a problem as I can use a single line text metafield instead. You just can’t use it for any numerical calculations.
But I will try the math filters. They look intriguing. Thank you!
Did you figure it out? I tried the “round: 2” math filter but it didn’t change anything. I’m using the “decimal” metafield type.
