判断整数是否为一位并在其前加零
Determine if the integer is one digit and add a zero before it
我需要检查int是否只有一位数字,如果是,我想在它前面加一个零。我有这段代码,但它不起作用。
var minutes2 = Int(minutes)
var minutessize: Int = sizeofValue(minutes2)
if minutessize < 2 {
var needStringHere = "0\(minutes2)"
let a: Int? = needStringHere.toInt()
minutes2 = a!
}
您可以只检查分钟计数是否小于 10:
var str = "\(minutes2)"
if (minutes2 < 10) { str = "0\(minutes2)" }
我需要检查int是否只有一位数字,如果是,我想在它前面加一个零。我有这段代码,但它不起作用。
var minutes2 = Int(minutes)
var minutessize: Int = sizeofValue(minutes2)
if minutessize < 2 {
var needStringHere = "0\(minutes2)"
let a: Int? = needStringHere.toInt()
minutes2 = a!
}
您可以只检查分钟计数是否小于 10:
var str = "\(minutes2)"
if (minutes2 < 10) { str = "0\(minutes2)" }