Skip to content

Instantly share code, notes, and snippets.

@girol
Last active July 4, 2022 15:26
Show Gist options
  • Save girol/f70a8c39715ce3f09d1cb50e8f37856c to your computer and use it in GitHub Desktop.
Save girol/f70a8c39715ce3f09d1cb50e8f37856c to your computer and use it in GitHub Desktop.
from decimal import *
PLACES = Decimal(10) ** -6
option1 = Decimal("1000.1111")
option2 = Decimal("300.2222")
option3 = Decimal("500.3333")
total = option1 - option2 - option3
print(total)
# output 199.5556
new_option = Decimal("100")
total = total + new_option
print(total)
print("----------------")
ctx = getcontext()
ctx.rounding = ROUND_HALF_UP
print(total.quantize(PLACES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment