Declare Float Variable
To declare a variable of type Float in Swift, use
: Float after the variable name.
var amount: Float
Let us write a swift program, in which we declare a variable with the name
amount, and declare this variable as type
Float. Later, we will assign a value
2.99 to this variable and print it.
import Foundation var amount: Float amount = 2.99 print(amount)
The type of the variable
Float, because of which we could assign a Float value to the variable.
We can also programmatically check the type of the variable
import Foundation var amount: Float print(type(of: amount))
We have learnt how to declare a variable of type Float in Swift.