Xcode Swift 3~将速度转换为整数

时间:2017-03-25 15:37:14

标签: swift xcode performance

我理解Int()是如何制作一些东西和整数但是当它与速度一起使用时这不起作用。这是我的代码:

    var speed: CLLocationSpeed = CLLocationSpeed()
    speed = location.speed * 2.23694


    if location.speed < 1 {
        speedLabel.text = "0"
    }
    else {
        speedLabel.text = "\(speed)"
    }

只是想知道如何将我的速度(mph)变成一个整数,因为目前我得到2个小数点,这使我的应用程序看起来很乱。提前致谢

1 个答案:

答案 0 :(得分:0)

使用舍入功能。在行动:

 22> round (1.6)
$R10: Double = 2
 23> Int(round (1.6))
$R11: Int = 2