I work with a number of numbers from 0.00 to 9999.99. I need to add thousands separator "˙", so it 1300,00should be 1˙300,00. NSNumberFormatter uses "," as a delimiter, so this is not good for me.
I tried to use
func formatNumber (i: Float) -> String {
var counter = 0
var correctedNumber = ""
if i > 999 {
for char in "\(i)".characters {
if counter == 1 {
correctedNumber += "˙" + "\(char)"
} else {
correctedNumber += "\(char)"
}
counter++
}
} else {
correctedNumber = "\(i)"
}
return correctedNumber
}
but it cannot format decimal numbers.
What is the right way to do this?
source
share