Skip to main content

Hello World Currencies

Posted by evanx on April 29, 2008 at 7:25 AM PDT

Since i've hardly being doing anything very useful of late, i decided it's time to return to my potentially generally useful efforts of a year ago vis-a-vis "countries of the world" and publish something for a start, to prod myself into "completing" the task, which i was enjoying immensely before it was interrupted by some months of travel.

So i started preparing Java code which listed the world's countries, currencies, capitals, timezones, internet TLD's, dialing codes, et al, with the help of Wikipedia with its ISO listings. It was helluva interesting, especially the corner cases eg. terrorities which due to current and/or historical political events, are potentially on the borderline of being countries as opposed to um, eg. a defacto self-governing terrority of the secessionist variety, possibly recognised by the UN but not by some country who considers them still part of their territory - you get the picture!

Also interesting are various "quirks" eg. the currency for the British Virgin Islands is the US Dollar. Or an island where the southern part is a territory of France and the northern part is a territory of Holland.

Having compiled these lists, i should reconcile with Locale.getAvailableLocales() via ISO codes, and
also the timezones of the capitals eg. reconciled with Java timezones via TimeZone. Also i need to update the country list eg. Kosovo declared independence, and it's status may have changed according to wikipedia?

I'll be publishing code on under Apache License in due course, so you can cut and paste, slice and dice it!
If you notice anything not quite right as we proceed, please lemme know, and we'll try to keep this thing correcto mundo, going forward.

Before i get onto the countries, here is teaser sample of the currencies...

putCurrency("AED", 2, "United Arab Emirates dirham");
putCurrency("AFN", 2, "Afghani");
putCurrency("ALL", 2, "Lek");
putCurrency("AMD", 2, "Armenian Dram");
putCurrency("ANG", 2, "Netherlands Antillian Guilder");
putCurrency("AOA", 2, "Kwanza");
putCurrency("ARS", 2, "Argentine Peso");
putCurrency("AUD", 2, "Australian Dollar");
putCurrency("AWG", 2, "Aruban Guilder");
putCurrency("AZN", 2, "Azerbaijanian Manat");
putCurrency("BAM", 2, "Convertible Marks");
putCurrency("BBD", 2, "Barbados Dollar");
putCurrency("BDT", 2, "Bangladeshi Taka");
putCurrency("BGN", 2, "Bulgarian Lev");
putCurrency("BHD", 3, "Bahraini Dinar");
putCurrency("BIF", 0, "Burundian Franc");
putCurrency("BMD", 2, "Bermudian Dollar");
putCurrency("BND", 2, "Brunei Dollar");
putCurrency("BOB", 2, "Boliviano");
putCurrency("BOV", 2, "Bolivian Mvdol (Funds code)");
putCurrency("BRL", 2, "Brazilian Real");
putCurrency("BSD", 2, "Bahamian Dollar");
putCurrency("BTN", 2, "Ngultrum");
putCurrency("BWP", 2, "Pula");
putCurrency("BYR", 0, "Belarussian Ruble");
putCurrency("BZD", 2, "Belize Dollar");
putCurrency("CAD", 2, "Canadian Dollar");
putCurrency("CDF", 2, "Franc Congolais");
putCurrency("CHE", 2, "WIR Euro (complementary currency)");
putCurrency("CHF", 2, "Swiss Franc");
putCurrency("CHW", 2, "WIR Franc (complementary currency)");
putCurrency("CLF", 0, "Unidades de formento (Funds code)");
putCurrency("CLP", 0, "Chilean Peso");
putCurrency("CNY", 2, "Yuan Renminbi");
putCurrency("COP", 2, "Colombian Peso");
putCurrency("COU", 2, "Unidad de Valor Real");
putCurrency("CRC", 2, "Costa Rican Colon");
putCurrency("CUP", 2, "Cuban Peso");
putCurrency("CVE", 2, "Cape Verde Escudo");
putCurrency("CYP", 2, "Cyprus Pound");
putCurrency("CZK", 2, "Czech Koruna");
putCurrency("DJF", 0, "Djibouti Franc");
putCurrency("DKK", 2, "Danish Krone");
putCurrency("DOP", 2, "Dominican Peso");
putCurrency("DZD", 2, "Algerian Dinar");
putCurrency("EEK", 2, "Kroon");
putCurrency("EGP", 2, "Egyptian Pound");
putCurrency("ERN", 2, "Nakfa");
putCurrency("ETB", 2, "Ethiopian Birr");
putCurrency("EUR", 2, "Euro");
putCurrency("FJD", 2, "Fiji Dollar");
putCurrency("FKP", 2, "Falkland Islands Pound");
putCurrency("GBP", 2, "Pound Sterling");
putCurrency("GEL", 2, "Lari");
putCurrency("GHC", 2, "Cedi");
putCurrency("GIP", 2, "Gibraltar pound");
putCurrency("GMD", 2, "Dalasi");
putCurrency("GNF", 0, "Guinea Franc");
putCurrency("GTQ", 2, "Quetzal");
putCurrency("GYD", 2, "Guyana Dollar");
putCurrency("HKD", 2, "Hong Kong Dollar");
putCurrency("HNL", 2, "Lempira");
putCurrency("HRK", 2, "Croatian Kuna");
putCurrency("HTG", 2, "Haiti Gourde");
putCurrency("HUF", 2, "Forint");
putCurrency("IDR", 2, "Rupiah");
putCurrency("ILS", 2, "New Israeli Shekel");
putCurrency("INR", 2, "Indian Rupee");
putCurrency("IQD", 3, "Iraqi Dinar");
putCurrency("IRR", 2, "Iranian Rial");
putCurrency("ISK", 0, "Iceland Krona");
putCurrency("JMD", 2, "Jamaican Dollar");
putCurrency("JOD", 3, "Jordanian Dinar");
putCurrency("JPY", 0, "Japanese yen");
putCurrency("KES", 2, "Kenyan Shilling");
putCurrency("KGS", 2, "Som");
putCurrency("KHR", 2, "Riel");
putCurrency("KMF", 0, "Comoro Franc");
putCurrency("KPW", 2, "North Korean Won");
putCurrency("KRW", 0, "South Korean Won");
putCurrency("KWD", 3, "Kuwaiti Dinar");
putCurrency("KYD", 2, "Cayman Islands Dollar");
putCurrency("KZT", 2, "Tenge");
putCurrency("LAK", 2, "Kip");
putCurrency("LBP", 2, "Lebanese Pound");
putCurrency("LKR", 2, "Sri Lanka Rupee");
putCurrency("LRD", 2, "Liberian Dollar");
putCurrency("LSL", 2, "Loti");
putCurrency("LTL", 2, "Lithuanian Litas");
putCurrency("LVL", 2, "Latvian Lats");
putCurrency("LYD", 3, "Libyan Dinar");
putCurrency("MAD", 2, "Moroccan Dirham");
putCurrency("MDL", 2, "Moldovan Leu");
putCurrency("MGA", 0, "Malagasy Ariary");
putCurrency("MKD", 2, "Denar");
putCurrency("MMK", 2, "Kyat");
putCurrency("MNT", 2, "Tugrik");
putCurrency("MOP", 2, "Pataca");
putCurrency("MRO", 2, "Ouguiya");
putCurrency("MTL", 2, "Maltese Lira");
putCurrency("MUR", 2, "Mauritius Rupee");
putCurrency("MVR", 2, "Rufiyaa");
putCurrency("MWK", 2, "Kwacha");
putCurrency("MXN", 2, "Mexican Peso");
putCurrency("MXV", 2, "Mexican Unidad de Inversion (UDI) (Funds code)");
putCurrency("MYR", 2, "Malaysian Ringgit");
putCurrency("MZN", 2, "Metical");
putCurrency("NAD", 2, "Namibian Dollar");
putCurrency("NGN", 2, "Naira");
putCurrency("NIO", 2, "Cordoba Oro");
putCurrency("NOK", 2, "Norwegian Krone");
putCurrency("NPR", 2, "Nepalese Rupee");
putCurrency("NZD", 2, "New Zealand Dollar");
putCurrency("OMR", 3, "Rial Omani");
putCurrency("PAB", 2, "Balboa");
putCurrency("PEN", 2, "Nuevo Sol");
putCurrency("PGK", 2, "Kina");
putCurrency("PHP", 2, "Philippine Peso");
putCurrency("PKR", 2, "Pakistan Rupee");
putCurrency("PLN", 2, "Zloty");
putCurrency("PYG", 0, "Guarani");
putCurrency("QAR", 2, "Qatari Rial");
putCurrency("ROL", 2, "Romanian Leu");
putCurrency("RON", 2, "Romanian New Leu");
putCurrency("RSD", 2, "Serbian Dinar");
putCurrency("RUB", 2, "Russian Ruble");
putCurrency("RWF", 0, "Rwanda Franc");
putCurrency("SAR", 2, "Saudi Riyal");
putCurrency("SBD", 2, "Solomon Islands Dollar");
putCurrency("SCR", 2, "Seychelles Rupee");
putCurrency("SDD", 2, "Sudanese Dinar");
putCurrency("SDG", 2, "Sudanese Pound");
putCurrency("SEK", 2, "Swedish Krona");
putCurrency("SGD", 2, "Singapore Dollar");
putCurrency("SHP", 2, "Saint Helena Pound");
putCurrency("SKK", 2, "Slovak Koruna");
putCurrency("SLL", 2, "Leone");
putCurrency("SOS", 2, "Somali Shilling");
putCurrency("SRD", 2, "Surinam Dollar");
putCurrency("STD", 2, "Dobra");
putCurrency("SYP", 2, "Syrian Pound");
putCurrency("SZL", 2, "Lilangeni");
putCurrency("THB", 2, "Baht");
putCurrency("TJS", 2, "Somoni");
putCurrency("TMM", 2, "Manat");
putCurrency("TND", 3, "Tunisian Dinar");
putCurrency("TOP", 2, "Pa'anga");
putCurrency("TRY", 2, "New Turkish Lira");
putCurrency("TTD", 2, "Trinidad and Tobago Dollar");
putCurrency("TWD", 2, "New Taiwan Dollar");
putCurrency("TZS", 2, "Tanzanian Shilling");
putCurrency("UAH", 2, "Hryvnia");
putCurrency("UGX", 2, "Uganda Shilling");
putCurrency("USD", 2, "US Dollar");
putCurrency("UYU", 2, "Peso Uruguayo");
putCurrency("UZS", 2, "Uzbekistan Som");
putCurrency("VEB", 2, "Venezuelan bolívar");
putCurrency("VND", 2, "Vietnamese đồng");
putCurrency("VUV", 0, "Vatu");
putCurrency("WST", 2, "Samoan Tala");
putCurrency("XAF", 0, "CFA Franc BEAC");
putCurrency("XCD", 2, "East Caribbean Dollar");
putCurrency("XOF", 0, "CFA Franc BCEAO");
putCurrency("XPF", 0, "CFP franc");
putCurrency("YER", 2, "Yemeni Rial");
putCurrency("ZAR", 2, "South African Rand");
putCurrency("ZMK", 2, "Kwacha");
putCurrency("ZWD", 2, "Zimbabwe Dollar");

where we specify the number of decimals.

Now to countries, with their currencies, languages, dialing codes, TLDs, and their capitals, with their coordinates, timezones and what-not, all cross-referenced via ISO codes! Baby steps... :)


ok so i'm doing some checking...

on my laptop, Locale.getAvailableLocales() gives 94 countries. This doesn't include Zimbabwe, and i know Zimbabwe exists and is a country! ;)

Wikipedia lists 245 entities including 193 states with general international recognition, 9 states lacking general recognition eg. Kosovo, and various dependent territories, eg. Reunion Island in the Atlantic Ocean is a territory of France.

I can't see how to list all currencies in java.util.CurrencyData, but using all available locales and Currency.getInstance(locale), i get 80 currencies (for the 94 locales). By comparison the list above is 181 currencies!

So I'm pretty sure i harvested the above list from the table of ISO 4217 currencies off wikipedia -

stephen that sounds great, i'll certainly take a look and get in touch :)

Evan, I've already got some code of this type setup at Joda-I!8N - It was built off the CLDR data. Perhaps you'd like to take a look and email me at scolebourne-joda-org. It would be nice to have one set of code for this kind of stuff if possible...

I'm wondering if you know that core Java already has an "official" list of currencies available from Currency.getInstance(locale) where locale is a locale with a country from Locale.getAvailableLocales(). And so we have indirectly the relation between a currency and a country.
It is a quite decent list of currencies (except perhaps latest changes).
And for each currency we have : getCurrencyCode() getDefaultFractionDigits() getSymbol() getSymbol(Locale) Moreover core Java also has a decent list of countries (and languages) with Locale.getAvailableLocales() as or each locale we have : getCountry() getDisplayCountry() getDisplayCountry(Locale) getDisplayLanguage() getDisplayLanguage(Locale) getISO3Country() getISO3Language() getLanguage() and more...
Of course, Java has no code INSEE for each country like in France. And this french administration INSEE also has a different list of countries for a reason unkown to me.
bye, Emeric Vernat

How does your list differ from that already in Java (see java.util.Currency)?

evernat, yes i do know about Locale.getAvailableLocales() - which i mentioned in the blog - however i used ISO lists from wikipedia as starting point as i recall, and now i need to reconcile against built-in data, which may be a slightly smaller, slightly out-of-date data set? I will get hands-on again on this stuff soon and then hopefully i'll remember what i was doing and why... ;)

For all i can remember (not much), the above list is just from the JRE, and therefore of virtually no use - embarrassing! But i expect and hope it's from the ISO list off wikipedia, and not from the JRE, and provides a more complete list? I'll check later when i have a sec, and compare with built-in JRE data...