Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a double with no Decimals?

I would like to display a Double with no decimals in Swift.

The location.speed comes from Map Kit. This is what I have tried:

let kmt = location.speed * (18/5)
let theKmt = Double(round(10*kmt)/10)

statusLabel.text = "km/t\(theKmt)"
like image 241
Paal Aune Avatar asked Sep 14 '25 15:09

Paal Aune


2 Answers

You're probably looking for this:

let d: Double = 1.12345
statusLabel.text = String(format: "%.0f", d)
like image 96
user3581248 Avatar answered Sep 17 '25 05:09

user3581248


 let d: Double = 1.23456
 let doub: Double = 1.23456
 print(String(format: "%.0f", d))
 print(Int(doub))
like image 24
SnowStorm-L Avatar answered Sep 17 '25 03:09

SnowStorm-L