Created
March 21, 2017 19:12
-
-
Save fedeisas/ecd878910f8ade7388ae5355ad24d779 to your computer and use it in GitHub Desktop.
Python Decimal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [13]: from decimal import * | |
In [14]: getcontext().prec = 6 | |
In [15]: ars_usd = Decimal(0.0641030) | |
In [16]: usd_ars = 1 / ars_usd | |
In [17]: usd_ars | |
Out[17]: Decimal('15.5999') | |
In [18]: price_usd = Decimal(100) | |
In [19]: price_ars = price_usd * usd_ars | |
In [20]: price_ars | |
Out[20]: Decimal('1559.99') | |
In [21]: # revert operation | |
In [22]: price_ars * ars_usd | |
Out[22]: Decimal('100.000') | |
In [23]: getcontext() | |
Out[23]: Context(prec=6, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999, capitals=1, flags=[Rounded, Inexact], traps=[InvalidOperation, DivisionByZero, Overflow]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment