四舍五入到小数点后第二位 [英] Rounding up to the second decimal place

查看:78
本文介绍了四舍五入到小数点后第二位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
PHP Round 函数 - 向上舍入 2 dp? >

我的问题是:

当我使用

ceil(3.6451895227869);

我喜欢

4

但是我想要

3.65

你能帮我吗?

UPDATE

请记住:这应该总是像四舍五入一样舍入到天花板

Please remember: This should always round to ceil like while rounding

3.6333333333333

不能是3.63,而应该是3.64

推荐答案

查看 http://www.php.net/manual/en/function.round.php

<?php

echo round(3.6451895227869, 2);

?>

编辑尝试使用这个自定义函数 http://www.php.net/manual/en/function.round.php#102641

EDIT Try using this custom function http://www.php.net/manual/en/function.round.php#102641

<?php 
function round_up ( $value, $precision ) { 
    $pow = pow ( 10, $precision ); 
    return ( ceil ( $pow * $value ) + ceil ( $pow * $value - ceil ( $pow * $value ) ) ) / $pow; 
} 

echo round_up(3.63333333333, 2);  // 3.64

?>

这篇关于四舍五入到小数点后第二位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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