Possible Duplicate:
PHP Round function - round up to 2 dp?
What my problem is:
When i use
ceil(3.6451895227869);
i get like
4
but i want
3.65
Can you help me out?
UPDATE
Please remember: This should always round to ceil like while rounding
3.6333333333333
it must not be 3.63 but should be 3.64
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
)
来源:https://stackoverflow.com/questions/8239600/rounding-up-to-the-second-decimal-place