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
What is 2.738 Round to Two Decimal Places? In the given number 2.738, the digit at the thousandths place is 8, so we will add 1 to the hundredths place digit. So, 3+1=4. Therefore, the value of 2.738 round to two decimal places is 2.74.
Just use %. 2f as the format specifier. This will make the Java printf format a double to two decimal places.
Head to Formulas > Math & Trig, and then choose either the “ROUNDUP” or “ROUNDDOWN” function from the dropdown menu. Enter the number (or cell) you want to round in the “Number” field. Enter the number of digits to which you want to round in the “Num_digits” field.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With