.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
Last updated
Was this helpful?