objective c - NSString formatting -


i'm changing pre-written code , video timelabel formatted so:

return [nsstring stringwithformat:@"%2d:%0.2d", minutes, seconds]; 

what's happening if minutes single digit, it's returning space before it, eg 4:49 has space before 4. how format there 2 characters in string if minutes arguments 2 digits, 1 character if minutes 1 digit?

you want following:

return [nsstring stringwithformat:@"%d:%02d", minutes, seconds]; 

simply using %d show number in many digits needs. , seconds shouldn't have decimal. %02d says show @ least 2 digits , left fill leading zeros ensure there 2 digits if needed.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -