Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Int to Double in Swift playground?

Tags:

ios

swift

I made a new Playground and wrote the code as following.

var value = 33 //This will make an integer type of value variable with value 33

value = 22.44 //This doesn't execute as its assigning Double/Float value to an integer.

I tried

1. 
value = Double(value)
value = 44.55 //Error here

2. 
value = Double(33.44) //Error here too.

3.
value : Double = 33.22 //Error here too.

Now what should I do to assign floating point to value.

NOTE: I am at learning level in Swift.

Thanks.

like image 225
Sam Shaikh Avatar asked Apr 13 '15 14:04

Sam Shaikh


1 Answers

Declaring var value = 33 will infer the type of value as Int. If you want to assign 33 and make value as Float or Double, you have to declare the type var value : Double = 33 or convert 33 to a Double while assign var value = Double(33).

like image 162
bontoJR Avatar answered Oct 21 '22 03:10

bontoJR