Last Updated: February 25, 2016
·
582
· mteece

Objective-C round 100ms NSTimeInterval to nearest 100

NSTimeInterval that returns a double, for example, that fires every 100ms with scheduledTimerWithTimeInterval:0.1 as the NSTimer.

double posNumber = 1157.483277;

// If number is positive, 1200.
int ms = 100 * round(posNumber / 100);

// Can also use floor() on positive, and ceil() on negative numbers