How to round up value in PHP?

Rio Eduardo picture Rio Eduardo · Jul 10, 2013 · Viewed 16.5k times · Source

I have a value like this:

$value = 2.3333333333;

and I want to round up this value into like this:

$value = 2.35;

I already tried round, ceil and etc but the result is not what I expected.

Please anyone help.

Thanks

Answer

Bathsheba picture Bathsheba · Jul 10, 2013

Taking your question literally, this will do it:

$value = (round($original_value / 0.05, 0)) * 0.05

i.e. will round to the nearest 0.05.

If, for some reason, you want to always round up to 0.05, use

$value = (round(($original_value + 0.025) / 0.05, 0)) * 0.05