0

I understand that Int() is how to make something and integer but this doesn't work when using it with speed. Here is my code:

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


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

Just wondering how to make my speed (mph) into an integer because currently I am getting 2 decimal points which make my app look messy. Thanks in advance

Matt
  • 131
  • 3
  • 10

1 Answers1

0

Use a rounding function. In action:

 22> round (1.6)
$R10: Double = 2
 23> Int(round (1.6))
$R11: Int = 2
GoZoner
  • 67,920
  • 20
  • 95
  • 145