Make a two-digit string from a single-digit integer
How can I have a two-digit integer in a a string, even if the integer is less than 10?
[NSString stringWithFormat:@"%d", 1] //should be @"01"
- Sorting NSDictionary
- Cocoa error 260
- Suppressing “'…' is deprecated” when using respondsToSelector
- Mac OS X: Getting detailed process information (specifically its launch arguments) for arbitrary running applications using its PID
- How to sort NSMutableArray using sortedArrayUsingDescriptors?
- How to get the computer's current volume level?
3 Solutions Collect From Internet About “Make a two-digit string from a single-digit integer”
I believe that the stringWithFormat specifiers are the standard IEEE printf specifiers. Have you tried
[NSString stringWithFormat:@"%02d", 1];
Use the format string
%02d. This specifies to format an integer with a minimum field-width of 2 characters and to pad the formatted values with 0 to meet that width. See
man fprintf for all the gory details of format specifiers.
If you are formatting numbers for presentation to the user, though, you should really be using
NSNumberFormatter. Different locales have wildly different expectations about how numbers should be formatted.
[NSString stringWithFormat:@"%00.02d", intValue]
This help me to convert 1 to 01.
- UIScrollView cancels UIPageViewController gestures when scrolling
- Saving And Loading Up A Highscore In Swift Using NSUserDefaults
- How to change IOS badge notification colour from default Red to other colours?
- google-tv development Environment
- Detect screen on/off from iOS service
- Are “Complex Numbers” already defined in Objective-C?
- How do I return a struct value from a runtime-defined class method under ARC?
- How can I find the address of a stack trace in LLDB for iOS
- type 'Any?' has no subscript members (using Firebase)
- How to know the current storyboard name?
- Left Align Cells in UICollectionView
- Get the length of a String
- Data from Plist is Incorrectly Ordered in UITableView
- Sending an iMessage as simple as possible iOS
- Can I watch an NSNotification from another class?