Mike D Mike D - 3 months ago 8
Swift Question

Swift how to format a large number with thousands seperators?

Is there a simple command to format 1.60543e+06 to 1,605,436???

resultFV.text = String.localizedStringWithFormat("%f", fv)

does not get it.

Answer

Swift xCode 6.3 , SOLVED ( I decided to lease the $ in): code If desire no $ in 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 –