# Numbers in Swift

> Learn how numbers work in Swift, from the main Int and Double types to sized integers like Int8 and UInt, and how to convert one numeric type to another.

Author: Flavio Copes | Published: 2021-05-31 | Canonical: https://flaviocopes.com/swift-numbers/

> This tutorial belongs to the [Swift](https://flaviocopes.com/swift-introduction/) series

In Swift, numbers have 2 main types: `Int` and `Double`.

An `Int` is a number without decimal point.
A `Double` is a number with decimal point.

Both use 64 bits, on modern computers that work with 64 bits, and 32 bit on 32-bit platforms.

The range of values they can store depends on the platform used, and can be retrieved using the `int` property of each type:

![Swift playground showing Int.min value -9223372036854775808 and Int.max value 9223372036854775807](https://flaviocopes.com/images/swift-numbers/Screen_Shot_2020-11-02_at_07.41.09.png)

Then, in addition to `Int` and `Double`, we have lots of other numeric types, mostly used to interact with APIs built in the past and that needed to interact with C or Objective-C, and you must be aware that we have them:

- `Int8` is an integer with 8 bits
- `Int16` is an integer with 16 bits
- `Int32` is an integer with 32 bits
- `Int64` is an integer with 64 bits

- `UInt8` is an unsigned integer with 8 bits
- `UInt16` is an unsigned integer with 16 bits
- `UInt32` is an unsigned integer with 32 bits
- `UInt64` is an unsigned integer with 64 bits

`UInt` is like `Int`, but unsigned, and it ranges from 0 to `Int.max * 2`.

`Float` is a decimal number with 32 bits.

Then using Cocoa APIs you might use other numeric types like CLong, CGFloat, and more. 

You will always use `Int` or `Double` in your code, and use those specific types to particular cases.

Any of those types can always be converted to `Int` and `Double` types, instantiating a number passing the value inside parentheses to `Double()` or `Int()`:

```swift
let age : UInt8 = 3
let intAge = Int(age)
```

You can also convert a number from `Double` to `Int`:

```swift
let age = Double(3)
let count = Int(3.14)
```

![Swift playground showing Double(3) converting to 3.0 and Int(3.14) converting to 3](https://flaviocopes.com/images/swift-numbers/Screen_Shot_2020-11-02_at_07.59.19.png)
