Convert Float to Int in Swift

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

    You can convert Float to Int in Swift like this:

    var myIntValue:Int = Int(myFloatValue)
    println "My value is \(myIntValue)"
    

    You can also achieve this result with @paulm's comment:

    var myIntValue = Int(myFloatValue)
    

提交回复
热议问题