ios - Format 9999999 into 9,999,999 (comma after every third digit) using NSNumberFormatter -
similar comma separated thousand nsstring stringwithformat specific use case.
how insert comma (,) after every third digit?
some cases:
- 9999999 → 9,999,999
- 1234 → 1,234
- 3432423455435435 → 3,432,423,455,435,435
the results expected regardless of locale or other circumstance.
you're looking nsnumberformatter
. easiest way use this:
nsstring *formatted = [nsnumberformatter localizedstringfromnumber:@(1234) numberstyle:nsnumberformatterdecimalstyle]; nslog(@"%@", formatted); // logs "1,234", depending on locale.
Comments
Post a Comment