.rounded()
// โญ๏ธ .toNearestOrAwayFromZero (ๅฐฑๆฏๅๆจไบๅ
ฅ)
(5.2).rounded() // 5.0
(5.5).rounded() // 6.0
(-5.2).rounded() // -5.0
(-5.5).rounded() // -6.0
let x = 6.5
// use rounding rules
x.rounded(.toNearestOrAwayFromZero) // round: 7.0
x.rounded(.towardZero)) // trunc: 6.0 โญ๏ธ
x.rounded(.up) // ceil : 7.0 โญ๏ธ
x.rounded(.down) // floor: 6.0 โญ๏ธ
// โญ๏ธ Int
Int(3.25) // 3
Int(3.7) // 3
Int(-3.3) // -3
Int(-3.7) // -3
Swift โฉ
Double โฉ
.rounded() - use .toNearestOrAwayFromZero rounding rule.
.rounded(_:) - use other rounding rules.
.round(), .round(_:) - round in place.
Int โฉ
init(_:)
Last updated