Use the following function to round, round, or round up.
round () → rounding fool () → truncate ceil () → Round up
ViewController.swift
let num = 7.5
let numRound = round(num)
//8 (rounded)
let numFloor = floor(num)
//7 truncated)
let numCeil = ceil(num)
//8 (rounded up)
ViewController.swift
let num = 3.1415
let numRound = round(num*10)/10
// 3.1 (rounded to the first decimal place)
let numFloor = floor(num*100)/100
// 3.14 (rounded down to the first decimal place)
let numCeil =ceil(num*1000)/1000
// 3.142 (rounded up to 4 decimal places)
that's all. please refer!
Recommended Posts