I'm trying to round number like this :
5,24785 => 5,49
5,74536 => 5,99
5,00000 => 5,00
I tried with https://php.net/round
But this return
5,24785 => 5,24
5,74536 => 5,74
5,00000 => 5,00
A php function can do it or I need to round up then remove 0.01 ?
Do you have some clues ?
You need using custom round function for this. Because rounding to 0.49 is not a standard way.
function rounder($num){
$fln = $num-floor($num);
if ($fln>0 and $fln<0.5) $fln=0.49;
else $fln=0.99;
return floor($num)+$fln;
}
echo rounder(5.24882);
There is no such a thing in php (i believe), you can do a manual check:
$number = "5.85458";
$decimal = $number - (int) $number;
if($decimal > 0 && $decimal < 0.5) $myNumber = (int) $number + 0.49; // x.49
if($decimal > 0.5) $myNumber = (int) $number + 0.99; // x.99
if($decimal == 0) $myNumber = (int) $number; // x.00
echo $myNumber;
Or just remove 0.01
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