Reputation: 408
I have a label that I'm updating every second which shows the hours with 100ths of an hour("1.67", etc.). I'm trying to get it to show correctly, but having trouble.
second = 781
let timeWorked = Float(second/3600)
let timeWorkedInHours = (String(format:"%.02f", timeWorked))
timeWorkedLabel.text = "\(timeWorkedInHours)"
I've tried a few things, but nothing that has worked yet. Any solutions?
Upvotes: 0
Views: 29
Reputation: 93181
I guess your second
is defined as Int
. Define it as Double
instead. Then you can get rid of the Float
cast too:
var second: Double = 0
// ...
let timeWorked = second / 3600.0
Upvotes: 1