Created
January 10, 2017 16:56
-
-
Save graup/7343ef1c643d66ea9ec003f71476ed85 to your computer and use it in GitHub Desktop.
The reason why you should be careful with currency amount calculation
This file contains 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
>>> from decimal import * | |
>>> VAT_RATE = Decimal('0.19') | |
>>> amount = Decimal('12.12') | |
>>> ((amount / (VAT_RATE + 1)).quantize(Decimal('1.00')) * (1+VAT_RATE)).quantize(Decimal('1.00')) | |
Decimal('12.11') | |
>>> ((amount / (VAT_RATE + 1)).quantize(Decimal('1.0000')) * (1+VAT_RATE)).quantize(Decimal('1.00')) | |
Decimal('12.12') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment