I have a NSString value of @"78000". How do I get this in currency format, i.e. $78,000 with it remaining an NSString.
You need to use a number formatter. Note this is also how you would display dates/times etc in the correct format for the users locale
// alloc formatter
NSNumberFormatter *currencyStyle = [[NSNumberFormatter alloc] init];
// set options.
[currencyStyle setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyStyle setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *amount = [NSNumber numberWithInteger:78000];
// get formatted string
NSString* formatted = [currencyStyle stringFromNumber:amount]
[currencyStyle release];
The decimal/cents at the end can be controlled as follows:
[currencyStyle setMaximumFractionDigits:0];
Here's the documentation link from apple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With