Swift playground - How to convert a string with comma to a string with decimal

前端 未结 5 1761
不知归路
不知归路 2020-12-03 17:52

I\'m new in the Swift world.

How can I converting a String with a comma to a String with a decimal?

The code work\'s fine with a dot (.)

The problem

5条回答
  •  独厮守ぢ
    2020-12-03 18:30

    var price = "2,25"
    price = price.replacingOccurrences(of: ",", with: ".")
    var priceFloat = (price as NSString).floatValue
    

提交回复
热议问题