Rounding up to the second decimal place [duplicate]

淺唱寂寞╮ 提交于 2019-11-30 01:19:53

Check out http://www.php.net/manual/en/function.round.php

<?php

echo round(3.6451895227869, 2);

?>

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

?>

You want round

round(3.6451895227869, 2, PHP_ROUND_HALF_UP);

The second argument is the precision, the flag tells round to always round up (like ceil)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!