How do you print out leading zeros for a float using the NSString type?
Input: 3.14
Desired output: 03.1
Using format @"%02.1f"
Output: 3.1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You want
@"04.1f". The 4 is the total width.As you can see from the documentation, the format strings conform to the IEEE printf specification.
The format string you’ve specified breaks down as follows: