Skip to main content
Post Closed as "Duplicate" by vacawama swift

I need to check if the int is only one digit and if it is, I want to add a zero in front of it. I have this code but it doesnt work.

var minutes2 = Int(minutes)  var minutessize: Int = sizeofValue(minutes2)  if minutessize < 2 {   var needStringHere = "0\(minutes2)"   let a: Int? = needStringHere.toInt()   minutes2 = a!  } 

I need to check if the int is only one digit and if it is, I want to add a zero in front of it. I have this code but it doesnt work.

var minutes2 = Int(minutes)  var minutessize: Int = sizeofValue(minutes2)  if minutessize < 2 {   var needStringHere = "0\(minutes2)"   let a:Int? = needStringHere.toInt()   minutes2 = a!  } 

I need to check if the int is only one digit and if it is, I want to add a zero in front of it. I have this code but it doesnt work.

var minutes2 = Int(minutes) var minutessize: Int = sizeofValue(minutes2) if minutessize < 2 { var needStringHere = "0\(minutes2)" let a: Int? = needStringHere.toInt() minutes2 = a! } 
Source Link
Deniz Yazar
  • 379
  • 2
  • 6
  • 12

Determine if the integer is one digit and add a zero before it

I need to check if the int is only one digit and if it is, I want to add a zero in front of it. I have this code but it doesnt work.

var minutes2 = Int(minutes) var minutessize: Int = sizeofValue(minutes2) if minutessize < 2 { var needStringHere = "0\(minutes2)" let a:Int? = needStringHere.toInt() minutes2 = a! }