Swift Code work’s fine with a dot (.) decimal.
The problem is when your using a comma (,) in your variables.
Origin of the problem:
Usually, the origin of the problem is from the Decimal Keyboard that use a comma (,) instead of a dot (.)
Like the French Decimal Keyboard
The result:
The reality is that you are loosing every thing after the decimal.
To understand, here’s the code you can test in Playground:
var price: String = "2,25" var priceFloat = (price as NSString).floatValue var costString = String(format:"%.2f", priceFloat)