Is there a simple command to format 1.60543e+06 to 1,605,436???
resultFV.text = String.localizedStringWithFormat("%f", fv)
does not get it.
The character used as the thousands separatorIn the United States, this character is a comma (,). In Germany, it is a period (.). Thus one thousand and twenty-five is displayed as 1,025 in the United States and 1.025 in Germany. In Sweden, the thousands separator is a space.
In Swift 3,
NumberFormatter.localizedString(from: NSNumber(value: whatever), number: NumberFormatter.Style.decimal)
Swift Xcode 6.3, SOLVED (I decided to leave the $ in the code). If you don't want a $ in the output, change .CurrencyStyle to .DecimalStyle
var fv = 3534234.55 var formatter = NSNumberFormatter() formatter.numberStyle = .CurrencyStyle formatter.maximumFractionDigits = 0; resultFV.text = formatter.stringFromNumber(fv) // result: $3,534,235 –
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With