IOS中數字的格式化

   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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章