Forum Moderators: coopster

Message Too Old, No Replies

Rounding a number up to a whole number

         

bobnew32

10:17 pm on Nov 17, 2003 (gmt 0)

10+ Year Member



I need a way of rounding any and every number with a decimal up to the next whole number (for page navigation sigh).

Examples

2.34938 --> 3
0.28374 --> 1
8.99999 --> 9
2.00001 --> 3

You get the idea, rounding is dificult in php.

jatar_k

10:24 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



not that difficult

ceil() [ca2.php.net] - is the one you want

there is also
round() [ca2.php.net]
floor() [ca2.php.net]

coopster

10:53 pm on Nov 17, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yeah, it's actually quite easy in PHP. Try rounding floats in Perl sometime! I had to (at the time) write my own function to do what PHP does by default with it's round [php.net] function to get the "banking" factor operating correctly.