iDevGames Forums
formatting value in a string - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: formatting value in a string (/thread-9604.html)



formatting value in a string - sefiroths - Dec 7, 2011 06:27 AM

if i have a value stored like:
Code:
long long unsigned x=1000000000000;
i'd like to have a
Code:
NSString *strx=[...];
so if i use NSLog or bitmapfont for this integer, what is displayed will be:
1,000,000,000,000
do exists this king od formatter?
thanks


RE: formatting value in a string - sefiroths - Dec 7, 2011 07:40 AM

found it:
long num = 1000000000;
NSNumberFormatter *fmt = [[NSNumberFormatter alloc] init];
fmt.positiveFormat = @"#,###";
NSLog(@"%@", [fmt stringFromNumber:[NSNumber numberWithLong:num]]);


RE: formatting value in a string - OneSadCookie - Dec 7, 2011 09:51 AM

You might consider a localized formatter for places where the thousands separator is not a comma.


RE: formatting value in a string - sefiroths - Dec 12, 2011 02:41 AM

thanks for suggestion! i'll look for it