PHP_ROUND_HALF_DOWN
will cover half , i.e. part 0.005
.
if you have 61.535
, when using PHP_ROUND_HALF_DOWN
you will get 61.53
- instead of 61.54
, which you should get with normal rounding.
Basicall, .005
half rounded down.
But 61.536
not half : .006
more than .005
; therefore, rounding this value gives 61.54
.
In your case, you can multiply the value by 100, use the floor () function and divide the result by 100 - I suppose this will give you what you expect:
$value = 61.536; $value_times_100 = $value * 100; $value_times_100_floored = floor($value_times_100); $value_floored = $value_times_100_floored / 100; var_dump($value_floored);
Gives me:
float(61.53)
source share