How to Get Nsnumberformatter Currency Style from Isocurrencycodes

How to get NSNumberFormatter currency style from ISOCurrencyCodes?

Use the setCurrencyCode: method of NSNumberFormatter.

[numberFormatter setCurrencyCode:@"EUR"];

or

[numberFormatter setCurrencyCode:@"USD"];

Keep in mind that even though the desired currency symbol will be used, the resulting currency value string is still going to be formatted based on the user's locale.

How to use NSNumberFormatter to display currency?

You can configure NSNumberFormatter like that :

NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
[numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numFormatter setCurrencySymbol:@"ct"];
[numFormatter setMultiplier:100];
NSNumber *myNumber = [NSNumber numberWithDouble:[@"0.058" doubleValue]];

How to get the Currency formatter with decimal and grouping separator in swift using ISOCode

The error comes from the way you cast your value to Int:

Int(1234567.89)

This rounds your floating-point value to 1234567 even before passing it to setAmountString.

Try casting it to Float instead, or not casting it at all. You also need to change your function signature from

func setAmountString (amountValue: Int, isoCodeStr: String)

to

func setAmountString (amountValue: Float, isoCodeStr: String)

NSNumberFormatter list of supported currencies

You can use the following to print the supported currencies.

NSLocale *locale = [NSLocale currentLocale];
for (NSString *code in [NSLocale ISOCurrencyCodes]) {
NSLog(@"%@ : %@", code, [locale displayNameForKey:NSLocaleCurrencyCode value:code]);
}

See if the out put is what you are looking for.

How to display correct Swedish currency on IOS?

I tried using

[currencyFormatter setCurrencyCode:@"SEK"];

but that did not give the correct output.

Then went through this link

A work around could be to append the string of the currency, though am not too sure whether that will fulfill your requirement.



Related Topics



Leave a reply



Submit