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.
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With