Hello, Under certain conditions I need to have a decimal round to a particular decimal value. As an example if I have a box that costs $23.03 under scenario A I need this to round to $23.10 but under scenario B I need it to round all the way to $23.20. Does anyone know the best way to approach this? Is there a more advanced way to control the round function? When asking this previously I was recommended to use ‘floor’ to bring it back to a base number, and then round from there or add the required amount, this unfortunately does not work, because sometimes we need to jump to the next divisible value of 20 or 10. So if its 23.43 it might need to end up at .50 or .60. So its a bit of a weird situation. Also is there a way to isolate the decimal via a function so I can evaluate it to make a decision microflow?
You could create a utility sub microflow that takes the price and the roundup value such as 0.10 or 0.20.
You would first need to divide the $price by the $roundup value. You then floor this value to round down, and then multiply it by the $roundup value. This gets you the lowest whole multiple. We can save this as $vPrice. You now need to check if you need to add the $roundup value to round up the price. You do this by doing a modulo on the $price with $roundup and seeing if it is zero. If it is zero we return the calculated $vPrice, if not we return $vPrice + roundup.
I hope this helps.
That is just math. First create a variable where you floor your initial value. So 23.43 becomes 23. Then substract the result from your initial value. You then get 23.43 – 23 = 0.43. Now multiply by 10 and floor again then it becomes 4. Now you have your decimal.