我想在Swift中顯示Double
沒有小數。顯示一個沒有小數點的雙精度?
location.speed
來自Map Kit。 這是我曾嘗試:
let kmt = location.speed * (18/5)
let theKmt = Double(round(10*kmt)/10)
statusLabel.text = "km/t\(theKmt)"
我想在Swift中顯示Double
沒有小數。顯示一個沒有小數點的雙精度?
location.speed
來自Map Kit。 這是我曾嘗試:
let kmt = location.speed * (18/5)
let theKmt = Double(round(10*kmt)/10)
statusLabel.text = "km/t\(theKmt)"
你可能在尋找這樣的:
let d: Double = 1.12345
statusLabel.text = String(format: "%.0f", d)
let d: Double = 1.23456
let doub: Double = 1.23456
print(String(format: "%.0f", d))
print(Int(doub))
感謝所有的答覆! 我真的很感激它。
我解決我的問題是這樣的:
let kmt = location.speed * (18/5)
let kmtLabel = Int(kmt)
statusLabel.text = "\(kmtLabel)"
你說的沒有小數是什麼意思?你應該整理一下嗎?下? – JAL
將四捨五入的值轉換爲「Int」而不是「Double」。 – rmaddy