Skip to content
Advertisement

How to round up value in PHP?

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

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement