1.2 Numbers

Int

  • whole numbers, will auto use 64-bit if available

Float

  • always a 32-bit decimal
  • 6 decimal place precision

Double

  • 64-bit decimal (default for decimal inference)
  • 15 decimal place precision
  • swift does not allow overflow (going beyond the range) by default

Declaration

// declaration - create but don't initialize<br>
var myVariable1: Int

// declaration - create/init with 0 value
var myVariable2 = Int()

// create and initialize with an initial value (preferred)
var myVariable3 = 24

// create multiple variables
var yes = 0, no = 0

Notation

// -> 51 prefix with 0b
let binaryNotation = 0b110011
// -> 10 prefix with 0o
let octalNotation = 0o12
// -> 50 prefix with 0x
let hexadecimalNotation = 0x32
// -> suffix with e-
let scientificNotation = 4.4e-7
// optional _ = easier to read
let longNumber = 1_000_000