iphone - 显示带逗号的整数 : 30000 --> 30, 000

标签 iphone objective-c cocoa

如何在 UILabel 中显示带有逗号的整数?

像这样: 30000 --> 30,000

我的英语不太好,所以我不知道要搜索什么。

感谢您的回答。

最佳答案

使用 NSNumberFormatter 并执行以下操作:

NSInteger integerValue=30000;
NSNumberFormatter *numberFormatterComma = [NSNumberFormatter new];
[numberFormatterComma setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *formatted = [numberFormatterComma stringFromNumber:[NSNumber numberWithInteger:integerValue]];
NSLog(@"--> %@",formatted);

现在您可以将格式化字符串放入标签中。

关于iphone - 显示带逗号的整数 : 30000 --> 30, 000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14302808/

相关文章:

objective-c - 如何获取 char 的实际值而不是 int 值

objective-c - Cocoa 应用程序意外退出

objective-c - Objective C 运行时如何查找已定义的消息?

objective-c - 自定义 NSFormatter 导致生成错误 "Class Unavailable: Custom Formatter with XCode versions prior to 4.1"

iphone - 在 SQLite 中获取表中填充行的总数

iphone - 如何解析 iOS 中有特殊字符的 xml 数据?

ios - 选择器 'datePicker' 没有已知的类方法

ios - 如何检查 iOS 或 macOS 上的互联网连接是否有效?

iphone 如何从月份编号获取月份名称?

iphone - 将 subview 添加到 UITableView 的父 View