You can do the same with NSString:
NSString *someString = [NSString stringWithFormat:@"$%.2lf", total];
Note that the format specifier is "% lf", not just "% f".
But it only works for US dollars. If you want to make your code more localizable, the right thing is to use a number format :
NSNumber *someNumber = [NSNumber numberWithDouble:total]; NSNumberFormatter *nf = [[NSNumberFormatter alloc] init]; [nf setNumberStyle:NSNumberFormatterCurrencyStyle]; NSString *someString = [nf stringFromNumber:someNumber];
Of course, it will not display the value calculated in US dollars with the euro symbol or something like that, so you either want to do all your calculations in the user's currency, or convert it to the user before displaying. You can find NSValueTransformer .
Caleb source share