0

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?

1
  • All the rounded prices must be in exceed: Ex: 4,53 must be 4,55 4,56 must be 4,60 Nov 19, 2014 at 16:00

1 Answer 1

2

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);
6
  • Where I can set this? In which file? Nov 19, 2014 at 16:02
  • You haven't said anything about what you are trying to do so i can't answer that - I've just answered question as you put it. Nov 19, 2014 at 16:10
  • I only need to round the products prices. The admin inserts "T-shirt 5,93€ ect.." and Magento modifies the price in 5,95€. Nov 19, 2014 at 16:17
  • See the edit - improved calculation. If you don't want the currency in the price use the non Magento method. Nov 19, 2014 at 16:22
  • Sorry for my inconvenience, but I don't know in which file of the core Magento does the calculation of the subtotal and the big total. For example /app/code/core/..... Nov 20, 2014 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.