0

I have installed Price Rounding plugin to my Magento site.

It works good, but I need to round price like that: 131.26 -> 131.25

The plugin gives me that: 131.26 -> 131.00

I know that it uses PHP math functions, but I don't know is there some PHP math functions that can give me 131.25 result.

Maybe there is another way to round price?

3

1 Answer 1

1

To round prices as .00 .25 0.50 0.75 you can use the following function:

function round_quarter($price){
  return round($price * 4) / 4;  
  // also possible floor($price * 4) / 4;
  // it depends on your business logic.
}

to check how it works try:

echo round_quarter(131.26);

3
  • if try bellow eg. $price = 13.70; $roundPrice = round($price * 4) / 4; echo $roundPrice;
    – Abdul
    Commented Jan 16, 2016 at 9:14
  • It is totally wrong
    – Abdul
    Commented Jan 16, 2016 at 9:14
  • and what is wrong, can you please explain? 13,70*4 = 54.8, round and get 55, divide and get nearest value of 13.75 If you want to get lower value 13.5 in our case, please use floor() instead of round.
    – Amasty
    Commented Jan 16, 2016 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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