The NSNumberFormatter class provides a simple means to format NSNumber objects. The class includes many pre-defined number format styles you can use and the table below list some of them.
Code below demonstrates how to use the NSNumberFormatter Class to format an NSNumber using the NSNumberFormatterCurrencyStyle format style.
// Create an NSNumber object, box a C floating-point number, then assign it to the NSNumber object NSNumber *profit = [NSNumber numberWithFloat:135457.89]; // Create an NSNumberFormatter object NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; // Set the formatter objec's style [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; // Format the profit object befor assinging it to a string object NSString *formattedProfit = [formatter stringFromNumber:profit]; // Display the formatted number string object NSLog(@"%@",formattedProfit);
Output
$135,457.89