Woodman
Woodman

Reputation: 1512

Converting Time into a Double Swift

I am new to Swift, and am stuck on a little problem. I have the current hour and minute(s) as Ints, and would like to know how to put them together, to create one whole number, like military times. WITHOUT CONVERTING TO STRING, as I need to be able to compare ( using < and >) later on.

EXAMPLE:

Upvotes: 0

Views: 1124

Answers (2)

Abizern
Abizern

Reputation: 150615

Multiply the current hour by 100 then add the number of minutes. From your example:

02 * 100 = 200
200 + 24 = 224

Upvotes: 2

Lukas
Lukas

Reputation: 3433

Here is a simple example

var num:Int = 02
print(num)
var num2:Int = 24

Double.init("\(num)\(num2)")

Upvotes: 0

Related Questions