Format Brazil currency in Objective C

1

I have a string already formatted, I would like to convert it to float and then to a number formatted for currency.

input output 1234.1 1234.1 or 1234.1

input output 1.234.10 1.234.10

    
asked by anonymous 03.01.2015 / 15:32

1 answer

1

I use this way:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSLocale *localizableIdentifier = [[NSLocale alloc] initWithLocaleIdentifier:@"pt_BR"];
[formatter setLocale:localizableIdentifier];
float money = 300.23f;
NSNumber *meuDinheiro = [NSNumber numberWithFloat:money];

NSString *newString = [formatter stringFromNumber:meuDinheiro];
NSLog(@"Você me deve: %@", newString);
    
08.01.2015 / 14:12