Currency conversions the geek way

There are many situations when I need to convert an amount of Euros to RON (Romanian Leu). There are a couple of sites that can do the conversion for you (even Google does this pretty well). However, none of them seem to be as accurate as the the National Bank of Romania, whose exchange rate is the only one that has any relevance for me. So most of the times I have to open the calculator, go the BNR website and use the exchange rate provided here, an issue that doesn’t work very well for a lazy ass like me.

Fortunately, BNR also provides an XML with the exchange rates for the most important currencies in a manner that is very easy to understand:

...
<Rate currency="DKK">0.4926</Rate>
<Rate currency="EGP">0.4291</Rate>
<Rate currency="EUR">3.6747</Rate>
<Rate currency="GBP">4.6020</Rate>
...

Luckily, Perl knows how to parse XMLs so we’re almost good to go. Now I am not Perl expert, nor want to become one very soon, but this sounded like something doable with a minimum amount effort.

What we need is to get the XML with an HTTP request, parse it and convert the given amount of money using the desired currency. So I created a tiny script convert2ron.pl that accepts two parameters: the currency identifier (EUR, USD, etc.) and the amount to be converted. I will not go into the details of how this script works as it’s pretty straight-forward (even for someone with a minimal understanding of Perl). So now I can convert all sorts of currencies to RON using calls like this:

$ ./convert2ron.pl EUR 245

and get results like these:

245 EUR = 900.30 RON

(rate is 3.6747)

Is this the geekiest way to do this, or what? And the geekness doesn’t stop here. Now I also have some scripts like eur2ron.sh and usd2ron.sh so I can do stuff like this all day:

$ eur2ron 456

So, if you want to convert international currencies to RON the geek way, here’s the download: http://cosminaru.ro/downloads/ron-convert.zip.

4 comments ↓

#1 Venci on 04.09.08 at 6:00 am

FUCK! I parsed their HTML code with regular expressions. FUCK! The idiot that I am!

#2 Venci on 04.09.08 at 6:01 am

FUCK!

#3 Cosmin Marginean on 04.09.08 at 6:04 am

And when you think that I thought of my self as the only geek to do this. Pfiuuu :)

#4 Gabriel Pop on 07.18.08 at 2:43 am

salut, daca ai IPhone, iti recomand http://ichange.ro/
e bazat tot pe xml-ul de la BNR.

Leave a Comment