In IOS , we can set the format of the NSDate output through NSDateFormatter 。Compared with the famous NSDateFormatter ,there is littte of people who know the NSNumberFormatter .In fact ,through NSNumberFormatter ,we also can set the NSNumber output .the code as follows:
NSNumberFormatter *formatter=[NSNumberFormatter alloc]init];
formatter.numberStyle=NSNumberFormatterDecimalStyle;
NSString *string=[NSString stringFromNumber:[NSNumber numberWithInt:123456789]];
Among them , NSNumberFormatter category has an attribute of numberStyle , which is an enum style , can make different digital format by setting different value 。This enum including : enum{
NSNumberFormatterNoStyle=KCFNumberFormatterNoStyle, // 123456789
NSNumberFormatterDecimalStyle=KCFNumberFormatterDecimalStyle, // 123,456,789
NSNumberFormatterCurrecncyStyle=KCFNumberFormatterCurrecncyStyle, // Y123456789
NSNumberFormatterPercentStyle=KCFNumberFormatterPercentStyle, // -539,222,988%
NSNumberFormatterScientificalStyle=KCFNumberFormatterScientificalStyle, // 1.23456789E8
NSNumberFormatterSpellOutStyle=KCFNumberFormatterSpellOutStyle, //一亿两千三百四十五晚六千七百八十九
}
the third and the last would output different results according to the different language areas of system setup.