在 Swift 3 中格式化数字 [英] Formatting Numbers in Swift 3
本文介绍了在 Swift 3 中格式化数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数字格式化为:123234234234 中的 123.234.234.234 取决于用户在文本字段中键入的内容.我不想管理货币,这不是关于货币,而是关于用户必须输入一个数字,并且这个数字的格式应该正确,以便于阅读.
I want to format number to this: 123.234.234.234 from 123234234234 depends on what the user types into the text field. I don't want to manage currency, it's not about currency, it is about the user has to type in a number and this number should be formatted correctly to be easier to read.
不是逗号,而是点.
我在整个研究中只发现了货币内容
I found only currency stuff in the whole research
推荐答案
您正在寻找的可能是 groupingSeparator
of NumberFormatter
let formater = NumberFormatter()
formater.groupingSeparator = "."
formater.numberStyle = .decimal
let formattedNumber = formater.string(from: number)
这篇关于在 Swift 3 中格式化数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文