0Pricing
Swift Academy · Lesson

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

  1. Integer Types and Their Ranges
  2. Floating-Point: Double vs Float
  3. Explicit Numeric Conversions
  4. Numeric Literals and Underscores
← Back to Swift Academy