PHP Round函数-舍入到2 dp? [英] PHP Round function - round up to 2 dp?

查看:77
本文介绍了PHP Round函数-舍入到2 dp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,我如何将值22.04496取整,使其变为22.05?看起来 round(22.04496,2)= 22.04.应该不是22.05吗?

In PHP how would i round up the value 22.04496 so that it becomes 22.05? It seems that round(22.04496,2) = 22.04. Should it not be 22.05??

预先感谢

推荐答案

您可以使用ceil并乘以10的幂进行除法.

you can do it using ceil and multiplying and dividing by a power of 10.

echo ceil( 1.012345 * 1000)/1000;

1.013

这篇关于PHP Round函数-舍入到2 dp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆