floor - How to round up in fraction part php -


i have value 2.3, 3.6,3.8 want value closest fraction.

suppose

when value 2.3 modified value 2.5 when value 2.2 modified value 2

i understand want round closest "half integer". if so, can use round() function little modificators.

because round() returns integers, need modify value before rounding , again after rounding in reverse way make work.

since want round 0.5, 1/2, need first multiply value 2, , divide after.

so pattern here is:

$roundedval = round($origval*2)/2; 

and examples question:

var_dump(round(2.3*2)/2); //2.5 var_dump(round(2.2*2)/2); //2.0 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -