How can I make sure a float will always be rounded up with PHP?

前端 未结 5 632
野趣味
野趣味 2020-12-09 08:33

I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows:

5条回答
  •  臣服心动
    2020-12-09 09:07

    I know this question has long since been answered, but it came up when I did a google search on the topic. If you want to round up with precision, then a good method would be to use the ceil function and times the number by how many decimal points you want to represent and then divide by that number.

    ceil(1024.321*100)/100
    

    would produce 1024.33

提交回复
热议问题