I try to round a number at 0.5
This is my examples :
5.1 > 5
2.4 > 2.5
1 > 1
6.8 > 7
6.2 > 6.5
I try with :
<?php
round((4.4 * 2) / 2)
?>
But :
5.4 > 5
4.7 > 5
instead of
5.4 > 5.5
4.7 > 4.5
Any idea ?
Why not just double the value, round on a full number and then devide by 2:
$res = round($value*2) / 2
That should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With