Page 1 of 1

Rounding numbers UP not down

Posted: Thu Feb 03, 2005 9:31 am
by Chris Corbyn
Hi does anybody know do I get the next nearest integer? Not just rounding to the NEAREST, it needs to always round in the same direction cos It's for a color picker and My gradient goes wrong if it round down for a particular value when all the others were rounded up

So 1.3 => 2 (not 1)
and 1.6 => 2 also

etc

Posted: Thu Feb 03, 2005 9:33 am
by JayBird
perhaps the ceil() funtion is what you are lookign for

http://uk2.php.net/manual/en/function.ceil.php

Posted: Thu Feb 03, 2005 10:11 am
by feyd
yep. ceil() is the function to use for that.

Posted: Thu Feb 03, 2005 10:30 am
by Chris Corbyn
Nice one thanks.... got it working now.

Only issue is the fact that it takes ages to process my script cos i have two loops each with 64 iterations nested one inside the other (one moves to the next row, the other moves to the adjacent cell) so that 64x64 = 4096 repetitions just to create a table with 4096 cells... even higher if the user wants to modify the max num colors available in the configuration...

Maybe I'll post my code in another thread and see if I could cut it down at all....

EDIT: this is just the initial pallette that loads... javascript will be used to change the pallette based on the user's hue selection... that's gonna crash the browser i'd say

Posted: Thu Feb 03, 2005 10:37 am
by Chris Corbyn
Actually that's a lie what I just said. I just got in from work and tested it on a "decent" PC and it went smoothly