Convert Float to Int in Swift

前端 未结 13 1956
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  旧时难觅i
    2020-11-28 23:22

    Suppose you store float value in "X" and you are storing integer value in "Y".

    Var Y = Int(x);
    

    or

    var myIntValue = Int(myFloatValue)
    

提交回复
热议问题