quick search:
 

Euro currency convertor

Submitted by: luistxo
Last Edited: 2004-10-14

Category: Python(Script)

Average rating is: 4.25 out of 5 (4 ratings)

Description:
The Euro will replace several national currencias in Europe in 2002.
This python script can make conversions in two directions.
Old currency <--> Euros

The rounding of amounts to cents or other units is done according
to official EU Regulation 1103/97 of 11 Sep 1997 (I believe)

1st draft, June 2001. Current one, December 2001.
Written by Luistxo (luistxo@eibar.org), complete newbie in Python and/or programming






Source (Text):
conversion = {
        'be' : [40.3399, 1],
        'de' : [1.95583, 100],
        'gr' : [340.750, 1],
        'es' : [166.386, 1],
        'fr' : [6.55957, 100],
        'ie' : [0.787564, 100],
        'it' : [1936.27, 1],
        'lu' : [40.3399, 1],
        'nl' : [2.20371, 100],
        'at' : [13.7603, 100],
        'pt' : [200.482, 1],
        'fi' : [5.94573, 100]
        }

am =float(amount)
a = conversion[cc]

if dir=='to':
 z1 = am/a[0]
 return round(z1*100)/100
else:
 p1 = am*a[0]
 if a[1] == 1:
   return int(round(p1*a[1])/a[1])
 return round(p1*a[1])/a[1]

Explanation:
Create a 'euros' script, with attributes like:
amount=1, cc='es', dir='.'

Then in DTML you can call it like

<dtml-var "euros(amount='5', cc='nl', dir='to')">

This converts that amount of Netherland Guilders into Euros.

<dtml-var "euros(amount='5', cc='nl')">

With no 'dir' argument, this converts that amount of Euros into Netherland Guilders.

cc is the country-code. In the dictionary, I've chosen Internet country domain names as the clue. You may change that, of course.

See a demo convertor made with this at http://www.codesyntax.com/Euro


Comments:

see also fmt=euros by rurban - 2004-10-14
see also the Zope2-2.4.0 fmt=euros patch
at http://www.zopelabs.com/cookbook/995917956