We help IT Professionals succeed at work.

rounding up

ChrisAndrews
ChrisAndrews asked
on

Hi,

I am trying to round up to a number to  two digits after the decimal, so:

4.331 becomes 4.34

'round' rounds to the closest (results are 4.33)

and using 'ceil' goes to the closest whole number, ie 5, there doesn't seem to be a way to set 'ceil' to round up to two digits after the decimal.

How do I do this?

Thanks,

Chris.

Comment
Watch Question

Commented:
Consider the following solution:

<?php

$float = 4.3312342345;
$rounded_float = ceil($float*100)/100;
echo $rounded_float;

?>

Of course you can adjust the value (100 in this example) to fit your needs. You have to multiply it with 10 / divide it by 10 for each digit more / less.

Kind regards,
nmeat

Author

Commented:
Hi,

Thank you, that works :)  It seems rather odd to me that php doesn't have  a function that will just round up to the nearest .xx

Chris

Explore More ContentExplore courses, solutions, and other research materials related to this topic.