Intern
What data type is used to represent floating-point numbers in Swift?
sobes.tech AI
Answer from AI
In Swift, the types Float and Double are used to represent floating-point numbers.
Float: Represents a 32-bit single-precision floating-point number.Double: Represents a 64-bit double-precision floating-point number.
Double is the default type for floating-point literals in Swift due to its greater precision.
let singlePrecision: Float = 3.14 // Explicitly specifying the Float type
let doublePrecision = 3.14 // Defaults to Double
The choice of type depends on the required precision and range of values. For most cases, Double is preferred.