panosl / django-currencies

django-currencies allows you to define different currencies, and includes template tags/filters to allow easy conversion between them.
http://pypi.python.org/pypi/django-currencies
BSD 3-Clause "New" or "Revised" License
94 stars 81 forks source link

rounding field on Currency model #18

Open ydaniv opened 9 years ago

ydaniv commented 9 years ago

Hi!

I have a working implementation of a rounding field on Currency model that enable cofiguring the rounding rules for each currency. It also includes a round() method on Currency that takes a value and retuns it rounded.

No tests for now, but just checking if this is something you'll be interested in adding to django-currencies.

Thanks!

panosl commented 9 years ago

I'm sure some people would want to fine-tune the way currencies handles the rounding, so if you can provide a patch for it, I'll include it!

racitup commented 5 years ago

I presume when you say rounding, you mean the number of decimal places? This is half-covered in the latest code by the addition of the info field. If you import the currency from the CurrencyISO source, what is called the ISO4217Exponent will be imported, which is the number of decimal places for the currency. The bit we're missing is the bit of code that looks this information up and uses it in the conversion. Unfortunately because other currency sources don't provide this information, we would have to also leave the default (currently 2)

racitup commented 5 years ago

I thought about adding the extra code to utils.py but it's already a bit ugly in there. If we were to do it properly as you say we should implement methods on the Currency model like the Money class here and here Also look at python-money and py-moneyed