Convert Float to Int in Swift

前端 未结 13 1930
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 23:16

I want to convert a Float to an Int in Swift. Basic casting like this does not work because these types are not primitives, unlike float

13条回答
  •  一向
    一向 (楼主)
    2020-11-28 23:28

    Use a function style conversion (found in section labeled "Integer and Floating-Point Conversion" from "The Swift Programming Language."[iTunes link])

      1> Int(3.4)
    $R1: Int = 3
    

提交回复
热议问题