PHP Round function
Posted
by
Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2012-06-08T16:29:24Z
Indexed on
2012/06/08
16:40 UTC
Read the original article
Hit count: 273
php
Is it possible to round a number where if it's 5 , just leave it , anything below 5 round down , anything above 5 round up?
EX:
5 * 1.35 = 6.75 .... leave it
5.2 * 1.35 = 7.02 .... 7.00
5.5 * 1.35 = 7.56 .... 8.00
I've formatted with round($n,0, PHP_ROUND_HALF_UP)
where $n is the product from the above calc , which leaves 6.75 but returns 7.02 for the next one. I also tried round($n,-1, PHP_ROUND_HALF_UP)
which gives me the 7.00 on the second calc but then of course won't return a 6.75 for the first, instead it returns 680.
This is a ticket markup calculation where the user enters the first number and is multiplied by the second. I actually remove the decimal because they don't want to see it, and they want this sort of customized rounding on the result.
Thanks,
Steve
© Stack Overflow or respective owner