objective-c round number to nearest 50

Viewed 12111

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

5 Answers

If number is positive: 50 * floor( number / 50 + 0.5 );

If number is negative: 50 * ceil ( number / 50 - 0.5 );

Related