Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift, Convert String To Double Error

i wrote a code to convert string to double but gives error :

Cannot convert the expression's type 'Double' to type 'NSString'

and my code is :

var first = previewLable.text
var second = label1.text

var number1: Double = (first as NSString).doubleValue
var number2: Double = (second as NSString).doubleValue

what i have to do to fix this error ???

Thanks

like image 524
Ali Sheikhi Avatar asked Sep 15 '26 03:09

Ali Sheikhi


1 Answers

Also if you're in Swift 2 you can use

Double("3.141592")

which gives an Optional Double, depending on whether it could be parsed

Double("hi")

would give nil

like image 106
Kametrixom Avatar answered Sep 17 '26 16:09

Kametrixom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!