我们都知道round方法是用来对浮点型数据四舍五入。
在Swift3中round的语法发生改变, 我们可以通过以下两种方式实现浮点型数据四舍五入
Darwin.round(3.14)
或者
3.14.rounded()
Darwin模块包含标准库中的 C 函数,在Swift中可以通过import Darwin使用 C 中的函数。
双击rounded()方法,我们可以看到rounded()其实是FloatingPoint协议中的一个方法,

1.png
参数rule是一个FloatingPointRoundingRule的枚举类型

2.png
相关文章
Add integral rounding functions to FloatingPoint
Swift and C Interop(简析Swift和C的交互)