Rounding and truncating with Double type in Swift
Forums:
let pi = 3.1415926535;
let piRound = round(pi * 1000) / 1000
//piRound is 3.142
let piTrunc = trunc(pi * 1000) / 1000
//piTrunc is 3.141
let piCeil = ceil(pi * 1000) / 1000
//piCeil is 3.142
- Log in to post comments