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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -