Sep-21-2019, 01:52 PM
Example with commercial round
Usually scientific rounding is used.
Usually scientific rounding is used.
def calc_tax(price, tax_in_percent): with decimal.localcontext() as ctx: ctx.rounding = decimal.ROUND_05UP # commercial round price = decimal.Decimal(price, ctx) tax = decimal.Decimal(tax_in_percent, ctx) / 100 return price * tax def get_input(): price = input('Price: ') tax = input('Tax (in %): ') result = calc_tax(price, tax) print(result) # you can work with result, but # before you print results, round them print(round(result, 2))You can also create a context with
decimal.Context()
, make your changes on the context and set the context with decimal.setcontext(ctx)
as global context.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!