Home > database >  Why does var x: Float = 4.5 Throws an Error?
Why does var x: Float = 4.5 Throws an Error?

Time:01-19

Anybody know why does my code throw an error everytime i assign a floating type variable?

I expect it not to throw any error

CodePudding user response:

Add F at the end of your code otherwise it will think that you are trying to assign a double

var x: Float = 4.5F

CodePudding user response:

4.5 is Double,

4.5f is Float.

  • Related