How to round of CGFloat value

lifemoveson picture lifemoveson · Jul 11, 2011 · Viewed 11.6k times · Source

Possible Duplicate:
NSNumberFormatter for rounding up float values

Currently, I calculate the scaling factor by using :

CGFloat scale = CGContextGetCTM(context).a;
NSLog(@"SCALE : %f", scale);

I receive a floating point value as : 0.124979, 0.249958, 0.499917. How can I use roundf to get it convert to 0.125, 0.250, 0.500 respectively.

Answer

Aravindhan picture Aravindhan · Jul 11, 2011

Try this........

NSLog(@"SCALE : %.3f", scale);
NSString *value = [NSString stringWithFormat:@"%.3f", theFloat];

Stolen from Previous SO answer