NumberFormatter - ObjectiveC
如何创建数字格式化程序以使用逗号格式化大数字?
例如,2389378.289 应变为 2,389,378.289
请注意,并不总是有三位小数,也不总是有小数。请使用 NSNumberFormatter。
谢谢!
How do I create a number formatter for formatting large numbers with commas?
For example, 2389378.289 should become 2,389,378.289
Note that there is not always three decimal places, nor is there always a decimal at all. Please use NSNumberFormatter.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Chuck 为您提供的格式最多支持 3 位小数。如果您的数字小于 3,它们就不会显示。 Chuck 也正确地表示您想查看 Unicode 数字格式指南,它对于解决数字格式问题非常有用。
The format Chuck gave you supports up to 3 decimal places. If you have a number with less than 3 they just don't show up. Chuck is also correct that you want to take a look at the Unicode number format guide, it is invaluable for number formatting issues.
其格式为
@"#,##0.###"
。请参阅Unicode 数字格式指南,了解如何使用的完整说明构造格式字符串。(另请注意,这在逗号和点反转或使用其他字符的区域设置中可以正常工作。)
The format for that would be
@"#,##0.###"
. Take a look at the Unicode number format guide for a full explanation of how to construct format strings.(Also note that this works correctly in locales where commas and dots are reversed, or where other characters are used.)