Convert Float to Int in Swift

前端 未结 13 1931
没有蜡笔的小新
没有蜡笔的小新 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:23

    var floatValue = 10.23
    var intValue = Int(floatValue)
    

    This is enough to convert from float to Int

提交回复
热议问题