var w = 6.5
w.round(.toNearestOrAwayFromZero)
// w == 7.0
// Equivalent to the C 'trunc' function:
var x = 6.5
x.round(.towardZero)
// x == 6.0
// Equivalent to the C 'ceil' function:
var y = 6.5
y.round(.up)
// y == 7.0
// Equivalent to the C 'floor' function:
var z = 6.5
z.round(.down)
// z == 6.0
4条答案
按热度按时间gywdnpxw1#
只需将
round
替换为floor
!1cklez4t2#
关于Swift 3.0:
jaql4c8m3#
SWIFT4+
不同情况下的舍入方法
iqjalb3h4#
关于Swift 5.0