Skip to content

Instantly share code, notes, and snippets.

@bodedra
Last active October 26, 2021 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodedra/6dd95f7e6fc734cbda2da45a7f55343f to your computer and use it in GitHub Desktop.
Save bodedra/6dd95f7e6fc734cbda2da45a7f55343f to your computer and use it in GitHub Desktop.
#python 3.x
import decimal
ctx = decimal.getcontext()
ctx.rounding = decimal.ROUND_HALF_UP
payment_discount = round((decimal.Decimal(amount * line.discount)/decimal.Decimal(100.0)), 2)
float(payment_discount)
amount = 611.50
discount = 10
before payment_discount = 61.1
after round half up = payment_discount = 61.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment