If I have a number int aNum = 2000000 how do I format this so that I can display it as the NSString 2,000,000?
If I have a number int aNum = 2000000 how do I format this
Share
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.
Don’t do your own number formatting. You will almost certainly not get all the edge cases right or correctly handle all possible locales. Use the
NSNumberFormatterfor formatting numeric data to a localized string representation.You would use the
NSNumberFormatterinstance method-setGroupingSeparator:to set the grouping separator to@","(or better yet[[NSLocale currentLocale] objectForKey:NSLocaleGroupingSeparator]; thanks @ntesler) and-setGroupingSize:to put a grouping separator every 3 digits.