I’m looking for a way to display “1” as “01”, so basically everything below 10 should have a leading 0.
What would be the best way to do this?
I know I can just use a simple if structure to do this check, but this should be possible with NSNumberformatter right?
If you just want an NSString, you can simply do this:
The
%02dis from C. %nd means there must be at least n characters in the string and if there are less, pad it with 0’s. Here’s an example:If the
numbervariable only was two digits long, it would be prefixed by eight zeroes. If it was 9 digits long, it would be prefixed by a single zero.If you want to use NSNumberFormatter, you could do this:
—-UPDATE——
I think this solves your problem: