Skip to content
Justice Tech School

Swift Numbers and Math

Int and Double support the usual math. Use abs, min, max, pow and sqrt from Foundation, and rounded() to round.

Example
import Foundation
print(abs(-7), min(3, 9), max(3, 9))
print(pow(2.0, 10), sqrt(81.0))
print(3.14159.rounded(), (2.567 * 100).rounded() / 100)

Exercise

Largest of two.

(3, 9)

Quiz Test

Which rounds a Double?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.