https://github.com/eventbrite/currint
https://github.com/eventbrite/currint
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eventbrite/currint
- Owner: eventbrite
- License: apache-2.0
- Created: 2014-07-10T22:49:46.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-17T19:06:28.000Z (about 2 years ago)
- Last Synced: 2023-05-17T19:27:52.380Z (about 2 years ago)
- Language: Python
- Size: 38.1 KB
- Stars: 0
- Watchers: 17
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
currint
=======Integer based, fixed-precision currency calculation.
A set of helper libraries to do currency calculations using only integers,
and with currency safety (you can't add two different currencies together).Represents all values as integer amounts in the minor unit (using
ISO 4217 exponent values), and can render numbers to strings or decimals too.Prevents addition of different currencies, inexact division, and a few other
things you really shouldn't be doing with currencies.Usage
-----Create values using ``currint.Amount.from_value_and_major`` if you have Decimals or strings::
>> currint.Amount.from_code_and_major("USD", "1.23")
Or using ``currint.Amount.from_value_and_minor`` if you already have minor values::
>> currint.Amount.from_code_and_minor("GBP", "4223")
You can then perform safe mathematics::
amount.apply_factor(2)
amount.divide_and_round(1.34)And output as decimals of major units if needed::
>> amount.to_major_decimal()
"42.23"Or directly use the minor values::
>> amount.value
4223
>> amount.currency.code
"GBP"