PHP round half up doesn't work

前端 未结 3 547
梦毁少年i
梦毁少年i 2021-01-25 19:40

I have this code


I want to round two decimals to half up, I expect a value as 0.58... but

3条回答
  •  无人及你
    2021-01-25 20:29

    function round_up($value, $places)
    {
      $mult = pow(10, abs($places));
      return $places < 0 ?
      ceil($value / $mult) * $mult :
      ceil($value * $mult) / $mult;
    }
    
    echo round_up(0.572,2);
    

    Hope this will work for you!!

提交回复
热议问题