[thelist] php - rounding decimals help

Phil Cooper Phil.Cooper at zirconsoftware.co.uk
Thu Oct 28 10:09:16 CDT 2004


> > round up to one decimal place eg 3.34 is rounded to 3.4.
> 
> Why not just write a quick function like this:
> 
> <?php
> function roundup ($num, $digits = 2) {
>     $shift = pow(10 , $digits);
>     return ((ceil($num * $shift)) / $shift);
> }
> 
> print roundup(3.342, 1);	# 3.4
> print roundup(3.342, 2);	# 3.35

perfect!

thank you

Phil


More information about the thelist mailing list