本文介绍了Int NSFormatter for swift 123456 to 1,23,456的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的值为123456,我希望在swift编程中将此值转换为1,23,456。我怎么能这样做?
I'm getting this value 123456 and I want to convert this value to 1,23,456 in swift programming. How can i do this ?
推荐答案
这是一种印度式数字格式,其中100,000
(写成1, 00,000)是一个。
This is an indian style number format, where 100,000(written as 1,00,000) is one "lakh".
从给出:
let formatter = NSNumberFormatter()
formatter.numberStyle = .DecimalStyle
formatter.locale = NSLocale(localeIdentifier: "en_IN") // English (India) locale
let number = 12345678
let string = formatter.stringFromNumber(number)!
println(string) // 1,23,45,678
Swift 3更新:
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
formatter.locale = Locale(identifier: "en_IN") // English (India) locale
let number = 12345678
let string = formatter.string(for: number)!
print(string) // 1,23,45,678
这篇关于Int NSFormatter for swift 123456 to 1,23,456的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!