I have a text return value of "3.5". I would need to format it to show "3.50"..
How do I do this?
It is all in strings as the value is extracted from a textfield
thanks
I have a text return value of "3.5". I would need to format it to show "3.50"..
How do I do this?
It is all in strings as the value is extracted from a textfield
thanks
You can just print with a String initializer
if let value = Double(stringValue) {
print("I want two precision point for \(value) to be \(String(format: "%.2f", value))")
}
It will output to I want two precision point for 3.5 to be 3.50\n
You can use the 'NSNumberFormatter' to format the amount values as given below:
let currencyFormatter: NSNumberFormatter = {
let currencyFormatter = NSNumberFormatter()
currencyFormatter.locale = NSLocale(localeIdentifier: "en")
currencyFormatter.numberStyle = .CurrencyStyle
return currencyFormatter
}()
func formattedStringForAmount(amount: String) -> String {
return currencyFormatter.stringFromNumber(Double(amount)!)!
}