Rounding up to the second decimal place

LIGHT picture LIGHT · Nov 23, 2011 · Viewed 62.1k times · Source

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

Answer

tomexx picture tomexx · Nov 23, 2011

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

?>