Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Various country's "currency decimal places width" in the iPhone-SDK

I read about NSLocaleCurrencySymbol, but where would I find the variable used to determine the "number of decimal places" used in a country's currency?

I.E. In the USA, it's common to see dollar amounts written with 2 decimal places: $1.23

What about many other countries?

like image 650
Susanna Avatar asked Apr 23 '10 19:04

Susanna


People also ask

How many digits to the right of decimal does the currency data type keep?

Currency variables are stored as 64-bit (8-byte) numbers in an integer format, scaled by 10,000 to give a fixed-point number with 15 digits to the left of the decimal point and 4 digits to the right.

How do you code 2 decimal places?

1. DecimalFormat(“0.00”) We can use DecimalFormat("0.00") to ensure the number is round to 2 decimal places.

What are decimal places of accuracy?

The decimal place accuracy of a number is the number of digits to the right of the decimal point. The decimal point is a period written between the digits of a number. If there is no decimal point, it is understood to be after the last digit on the right and there is no place (zero place) accuracy.


2 Answers

There are a number of other countries that display a different number of decimal places. 2 is the majority, 0 (no cents in their currency, e.g., Japan) is the largest minority, 3 is used in just a few. No other number that I know off. When exchange rates are quoted, more decimals are typically used. The currencies with 0 and 3 that I'm aware of are shown below.

The ISO currency codes can be found at: http://www.iso.org/iso/support/currency_codes_list-1.htm http://en.wikipedia.org/wiki/ISO_4217 or http://www.currency-iso.org/en/home/tables/table-a1.html.

ISO Code           Currency Decimal places  ADP Andoran Peseta 0 AFA Afghani Afghani 0 BEF Belgian franc 0 BHD Bahraini dinar 3 BIF Burundi franc 0 BYB Belorussian rubel (old) 0 BYR Belorussian rubel (new) 0  CLP Chilean peso 0 COP Colombian peso 0 DJF Djibouti franc 0 ECS Ecuadorian sucre 0 ESP Spanish peseta 0 GNF Guinea franc 0 GRD Greek drachma 0 HUF Hungarian forint 0 IDR Indonesian rupiah 0 IQD Iraqui dinar 3 ITL Italian lira 0 JOD Jordan dinar 3 JPY Japanese yen 0 KMF Comoros franc 0 KRW South Korean won 0 KWD Kuwaiti dinar 3 LAK Laos new kip 0 LUF Luxembourg franc 0 LYD Libyan dinar 3 MGF Madagascan franc 0 MZM Mozambique metical 0 OMR Omani rial 3 PTE Portugese escudo 0 PYG Paraguay guarani 0 ROL Roumanian Lei 0 RWF Rwanda franc 0 TJR Tadzhikistani rubel 0 TMM Turkmenistani manat 0 TND Tunesian dinar 3 TPE Timor escudo 0 TRL Turkish lira 0 TWD New Taiwan dollar 0 UGX Uganda shilling 0 VND Vietnamese dong 0 VUV Vanuata vatu 0 XAF CFA Franc BEAC 0 XOF CFA Franc BCEAO 0 XPF CFP Franc 0 
like image 158
Jorge Brana Avatar answered Oct 10 '22 10:10

Jorge Brana


In iOS 6 (and possibly earlier) you can find out the number of digits after the decimal place of a currency from the minimumFractionDigits property of an NSNumberFormatter set to the correct locale:

 void (^currency_test)(NSString *) = ^(NSString *locale) {     NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];     [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:locale]];     [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];     NSLog(@"%@: %@ (minimumFractionDigits = %d)", locale, [formatter stringFromNumber:@(1000)], [formatter minimumFractionDigits]); };  currency_test(@"en_US"); currency_test(@"nl_NL"); currency_test(@"de_DE"); currency_test(@"fr_FR"); currency_test(@"jp_JP"); currency_test(@"ar_JO");  en_US: $1,000.00 (minimumFractionDigits = 2) nl_NL: € 1.000,00 (minimumFractionDigits = 2) de_DE: 1.000,00 € (minimumFractionDigits = 2) jp_JP: ¥ 1000 (minimumFractionDigits = 0) ar_JO: ١٠٠٠٫٠٠٠ د.أ.‏ (minimumFractionDigits = 3) 

Note that you must call [formatter setNumberStyle:NSNumberFormatterCurrencyStyle] before the minimumFractionDigits property is populated with the correct value (that one only took me half an hour to work out!)

like image 41
Robert Atkins Avatar answered Oct 10 '22 11:10

Robert Atkins