Format Brazil Currency in Objective C

Asked

Viewed 334 times

1

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

exit entrance 1.234,10 1234.1 or 1234.1

exit entrance 1.234.10 1.234,10

  • 5

    If you’re using float for money you already have a much more serious problem than formatting: http://answall.com/q/40045/101 and http://answall.com/q/38138/101 and I think the formatting has been answered here: http://answall.com/q/8190/101

1 answer

1

I use it like this:

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.