Swift - Write program to fix error in string conversion


The following code snippet causes the compiler to flag an error. Fix it.

var amount = "1200"
var rate = "1.27"
var result = amount * rate


You can cast the strings as NSString first and then use the doubleValue property to extract their double values:


var amount = "1200"
var rate = "1.27"
var result = (amount as NSString).doubleValue * (rate as NSString).doubleValue
print(result)//from   www .j av  a2s  .  c om

Related Exercise