swift版本
let formatter = NumberFormatter()
formatter.numberStyle = NumberFormatter.Style(rawValue: UInt(CFNumberFormatterRoundingMode.roundHalfDown.rawValue))!
let string = formatter.string(from: NSNumber(value: 5))
print("str = \(string ?? "")")
object-c版本
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = kCFNumberFormatterRoundHalfDown;
NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:5.66]];
NSLog(@"str = %@", string);
这个主要是用NSNumberFormatter
这个class提供的格式化方法,好记性不如烂笔头