iOS Round Double value to 2 decimal digits and round 3rd decimal digit up

I have I double value like this one 17.125. It should be rounded up to 17.13ios

If I use the simple method like %.2f it shows me 17.12 I also followed several methods described in other threads here like using NumberFormatter and so on - but without luck.git

Maybe someone has an advice for me to fix this problem? Do I have to round it on my own?post

 

Try This:this

float number=17.125;
NSNumberFormatter *format = [[NSNumberFormatter alloc]init];
[format setNumberStyle:NSNumberFormatterDecimalStyle];
[format setRoundingMode:NSNumberFormatterRoundHalfUp];
[format setMaximumFractionDigits:2];
NSString *temp = [format stringFromNumber:[NSNumber numberWithFloat:number]];
NSLog(@"%@",temp);

http://stackoverflow.com/questions/15109963/ios-round-double-value-to-2-decimal-digits-and-round-3rd-decimal-digit-upspa

相關文章
相關標籤/搜索