Swift Basics

Doubles

Double is short name for “double-precision floating-point number”, and it’s a fancy way of saying that it holds fractional values such as 24.5, or 3.141592654.

Whenever you create a variable with a fractional number, Swift automatically gives that variable the data type Double. For example:

var pi = 3.141

Of course, you can specify the data type manually if you like:

var pi: Double = 3.141

Doubles are different from integers, and you can’t mix them by accident, if you try it, you’ll get an error:

var pi: Int = 3.141

enter image description here

Ok, delete the last line before we move on.

   
« Previous: Strings and integers Next: Booleans »