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