2017-08-22 64 views
0

我想在Swift中顯示Double沒有小數。顯示一個沒有小數點的雙精度?

location.speed來自Map Kit。 這是我曾嘗試:

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

statusLabel.text = "km/t\(theKmt)" 
+0

你說的沒有小數是什麼意思?你應該整理一下嗎?下? – JAL

+0

將四捨五入的值轉換爲「Int」而不是「Double」。 – rmaddy

回答

1

你可能在尋找這樣的:

let d: Double = 1.12345 
statusLabel.text = String(format: "%.0f", d) 
2
let d: Double = 1.23456 
let doub: Double = 1.23456 
print(String(format: "%.0f", d)) 
print(Int(doub)) 
-1

感謝所有的答覆! 我真的很感激它。

我解決我的問題是這樣的:

let kmt = location.speed * (18/5) 
    let kmtLabel = Int(kmt) 



    statusLabel.text = "\(kmtLabel)" 
相關問題