Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the smallest unit of a currency in python

Tags:

python

a credit card provider needs the transaction amount in cents or smallest available unit of the currency. since I want the code to be portable I have to get the smallest unit of a given currency and it's factor to the main unit. I've tried to get it from the locale module but i had no luck.

http://docs.python.org/library/locale.html

Example

i have a currency code as described in iso 4217

EUR for Euro

then i need 1 Euro is 100 Eurocents (only the information 1/100, no text is needed)

according to wikipedia there currencies which have more than 2 units like the old pund sterling

like image 997
frog32 Avatar asked Sep 04 '12 13:09

frog32


People also ask

What is the smallest unit of currency?

A penny is a coin ( pl. pennies) or a unit of currency (pl. pence) in various countries. Borrowed from the Carolingian denarius (hence its former abbreviation d.), it is usually the smallest denomination within a currency system.


1 Answers

Alternatively cou can use following simple mapping module: http://pastebin.com/K7kVXi8P

Save this pastebin into a module within your project (e.g. simple_currency_helper.py) and use the map (or the helper method get_currency_subunit) to get out the currency subunit for a given ISO-Code.

>>> from simple_currency_helper import get_currency_subunit
>>> print get_currency_subunit('TND')
1000
like image 54
Colin O'Coal Avatar answered Oct 18 '22 20:10

Colin O'Coal