Reputation: 21
I have this code
var i = 1
println(i) //result is 1
println(%02i) //is wrong
I want it to output 01 instead of 1
Upvotes: 0
Views: 1240
Reputation: 1415
Your best bet is still going to be NSString formatting:
var i = 3
println("someInt is now \(i)")
// prints "someInt is now 1"
println(NSString(format:"%.2f",i))
// prints "someInt is now 01"
May be this help you.
Upvotes: 0
Reputation: 64674
Unfortunately, you can't format swift strings like that (as far as I know.) You can try to use an NSString though.
println(NSString(format:"%02i", i))
Upvotes: 2