NSNumberFormatter 亲测

点前18个8,点后12个8

- (void)viewDidLoad {
    NSLog(@"结果为:%@%@",[ViewController getFormatterWithDoubleValue:888888888888888888.888888888888]);
}
+ (NSString *)getFormatterWithDoubleValue:(double)doubleValue
{
    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    return [formatter stringFromNumber:[NSNumber numberWithDouble:doubleValue]];
}

对应输出结果:

NSNumberFormatterNoStyle
结果为:888888888888889000
NSNumberFormatterDecimalStyle
结果为:888,888,888,888,889,000
NSNumberFormatterCurrencyStyle
结果为:$888,888,888,888,889,000.00
NSNumberFormatterPercentStyle
结果为:88,888,888,888,888,900,000%
NSNumberFormatterScientificStyle
结果为:8.88888888888889E17
NSNumberFormatterSpellOutStyle
结果为:eighteen quadrillion fourteen trillion three hundred ninety-eight billion five hundred nine million four hundred eighty-one thousand nine hundred eighty-four
NSNumberFormatterOrdinalStyle
结果为:888,888,888,888,889,000th
NSNumberFormatterCurrencyISOCodeStyle
结果为:USD888,888,888,888,889,000.00
NSNumberFormatterCurrencyPluralStyle
结果为:888,888,888,888,889,000.00 US dollars
NSNumberFormatterCurrencyAccountingStyle
结果为:$888,888,888,888,889,000.00

NSNumberFormatterRoundCeiling 
结果为:888888888888889000
NSNumberFormatterRoundFloor 
结果为:888,888,888,888,889,000
NSNumberFormatterRoundDown //(输出会根据系统设置的语言区域的不同而不同)
结果为:$888,888,888,888,889,000.00
NSNumberFormatterRoundUp 
结果为:88,888,888,888,888,900,000%
NSNumberFormatterRoundHalfEven 
结果为:8.88888888888889E17
NSNumberFormatterRoundHalfDown //(输出会根据系统设置的语言区域的不同而不同)
结果为:eighteen quadrillion fourteen trillion three hundred ninety-eight billion five hundred nine million four hundred eighty-one thousand nine hundred eighty-four
NSNumberFormatterRoundHalfUp 
结果为:888,888,888,888,889,000th

你可能感兴趣的:(NSNumberFormatter 亲测)