iOS 中数字的格式化处理
来源:互联网 发布:.com.cn是什么域名 编辑:程序博客网 时间:2024/06/05 00:26
最近越来越多的App 中对数字采用分割数字格式,看起来更直观。iOS中NSNumberFormatter 可以帮我们从容处理,使用方式类似于NSDateFormatter。代码如下:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];formatter.numberStyle = NSNumberFormatterDecimalStyle;NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:123456789]];NSLog(@"Formatted number string:%@",string);输出结果为: Formatted number string:123,456,789其中NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值可以输出不同的数字格式。该枚举包括:
enum {
NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle,
NSNumberFormatterDecimalStyle = kCFNumberFormatterDecimalStyle,
NSNumberFormatterCurrencyStyle = kCFNumberFormatterCurrencyStyle,
NSNumberFormatterPercentStyle = kCFNumberFormatterPercentStyle,
NSNumberFormatterScientificStyle = kCFNumberFormatterScientificStyle,
NSNumberFormatterSpellOutStyle = kCFNumberFormatterSpellOutStyle
};
typedef NSUInteger NSNumberFormatterStyle;
各个枚举对应输出数字格式的效果如下:
Formatted number string:123456789
Formatted number string:123,456,789
Formatted number string:¥123,456,789.00
Formatted number string:-539,222,988%
Formatted number string:1.23456789E8
Formatted number string:一亿二千三百四十五万六千七百八十九
0 0
- iOS 中数字的格式化处理
- iOS中数字的格式化
- iOS中数字的格式化
- iOS中数字的格式化
- iOS中数字的格式化
- iOS中数字的格式化
- IOS中数字的格式化
- ios iOS中数字的格式化 NSNumberFormatter
- iOS中数字的格式化 NSNumberFormatter
- iOS中数字的格式化 NSNumberFormatter
- iOS 数字的格式化(NSNumber格式化)
- IOS-NSNumberFormatter--数字的格式化
- ios中数字的格式化(金额千分位格式化显示)
- Java中数字的格式化
- SQL中数字的格式化
- iOS中对字符串类型的金额进行格式化处理
- iOS 用NSNumberFormatter进行数字的格式化
- iOS 用NSNumberFormatter进行数字的格式化
- UI资料
- Java的StringBuffer类
- 【codevs 2975】与2,3,5无关的数
- Head First C# 实验室 赛狗日
- C++之为什么对引用变量取地址得到的是被引用变量的地址
- iOS 中数字的格式化处理
- 防止字典参数缺少发生意外崩溃的解决方法
- 采用先进的视觉技术测试图形用户界面:工具、技术和实践
- 静态数组实现栈
- .ini文件转换为.xml文件
- U3D——刀光轨迹插件的改进
- MFC+Direct2D简化坐标缩放
- POJ1655 Balancing Act 求树的重心
- 淘宝内部分享:怎么跳出MySQL的10个大坑