Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round up value in PHP?

Tags:

php

roundup

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

like image 983
Rio Eduardo Avatar asked Jul 10 '13 07:07

Rio Eduardo


1 Answers

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
like image 165
Bathsheba Avatar answered Sep 23 '22 04:09

Bathsheba