Explicit Numeric Conversions
Convert between numeric types deliberately to avoid errors.
Swift Requires Explicit Conversion
Swift does not automatically convert between numeric types. To combine an Int and a Double, you must convert one explicitly.
let count = 3
let price = 2.5
let total = Double(count) * price
print(total)Why No Implicit Conversion
Implicit conversions can silently lose data or change meaning. Swift makes you state intent, preventing subtle bugs.
let whole = 7
let fraction = 0.5
let result = Double(whole) + fraction
print(result)All lessons in this course
- Integer Types and Their Ranges
- Floating-Point: Double vs Float
- Explicit Numeric Conversions
- Numeric Literals and Underscores