I need to round the products prices with precision 2, but with the last decimal equal to 0 or 5. Example:
16,50€
76,70€
5,05€
Inserted prices have precision 4.
16,5963 need to be -> 16,60
16,5388 need to be -> 16,55
How can I do it?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI need to round the products prices with precision 2, but with the last decimal equal to 0 or 5. Example:
16,50€
76,70€
5,05€
Inserted prices have precision 4.
16,5963 need to be -> 16,60
16,5388 need to be -> 16,55
How can I do it?
Magento way of generating a price with currency symbol:
$pow = pow(10, 2);
$someprice = (ceil($pow * $someprice) + ceil($pow * $someprice - ceil($pow * $someprice))) / $pow;
$someprice = Mage::helper('core')->currency($someprice, true, false);
Note that you need to pass false as the third argument if you don't want to returned price to have a containing <span class="price">
element - both the second and third arguments are true by default.
Non Magento way to just format a float value for 2 decimal places:
$pow = pow(10, 2);
$someprice = (ceil($pow * $someprice) + ceil($pow * $someprice - ceil($pow * $someprice))) / $pow;
$someprice = number_format($someprice, 2);