Rounding numbers UP not down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Rounding numbers UP not down

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

perhaps the ceil() funtion is what you are lookign for

http://uk2.php.net/manual/en/function.ceil.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yep. ceil() is the function to use for that.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
Post Reply