Swift - Write program to fix error in string conversion

Requirements

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

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

Hint

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

Demo

var amount = "1200"
var rate = "1.27"
var result = (amount as NSString).doubleValue * (rate as NSString).doubleValue
print(result)//  w  ww  .  j  av a 2  s  . c  o  m

Related Exercise