views:

93

answers:

2

How can I round a number to the nearest X value (for example 50)

i.e 47 would be 50

24 would be 0

74 would be 50

99 would be 100

etc...

I really have no idea where to start looking into how to do this...

P.S. Im using cocoa-touch for the iPhone

Thanks a lot Mark

+3  A: 

Divide by 50, round to the nearest integer, and multiply by 50.

dan04
+3  A: 

Do this:

Number * floor((Number/50)+0.5)
NSArray
Or, "the same way you might do it in C" ...
Joshua Nozzi
thanks both ways worked just fine
Mark