Forum Moderators: coopster

Message Too Old, No Replies

round up with php

always round up to 2 decimal places

         

kermey

10:35 am on Jul 7, 2004 (gmt 0)

10+ Year Member



This is an odd problem. If my script has an amount, say 0.61222, I need to round it up to the nearest 2 decimal place. round() will round it down (properly) but i need to always round up so 0.61222 would become 0.62. ceil() doesnt work, it rounds the whole lot up to 1. Any ideas?

dreamcatcher

3:30 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use number_format to format decimal places. Dont think this rounds the decimal number up though.

httpwebwitch

3:36 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ceil($x*100)/100

ergophobe

3:51 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




$x = 0.1612213

$x = ceil(100 * $x)/100;

httpwebwitch

3:55 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



is there an echo in here? :-)

Stretch out your math brain with this one:

function roundup($x,$places){
$cent=pow(10,$places);
return ceil($x*$cent)/$cent;
}

ergophobe

4:06 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry, I was writing while you were posting....

Sorry, I was writing while you were posting....

hey, there is an echo