Floating-Point: Double vs Float
Choose between Double and Float and handle precision.
Floating-Point Types
Swift has two main floating-point types: Double (64-bit) and Float (32-bit). They represent numbers with fractional parts.
let d: Double = 3.14159
let f: Float = 3.14159
print(d, f)Double Is the Default
When you write a decimal literal without a type annotation, Swift infers Double. Double offers more precision than Float.
let value = 2.5
print(type(of: value))All lessons in this course
- Integer Types and Their Ranges
- Floating-Point: Double vs Float
- Explicit Numeric Conversions
- Numeric Literals and Underscores