I'm looking for something to round up and round down at 1,2, and -1 decimal points in python, I have written some logic through it I am able to get the right values for +ve points but still looking round down -ve values.
my code is as -:
import decimal
outcome = '2156.24611496733'
rounding="Alwayes Down"
decimal_place = -1
# for positive values
if rounding == "Alwayes Up":
decimal.getcontext().rounding = decimal.ROUND_UP
elif rounding == "Alwayes Down":
decimal.getcontext().rounding = decimal.ROUND_DOWN
# for negative values
if rounding == "Alwayes Down":
print(round(float(outcome), decimal_place))
rounding_string = "1." + "0"*int(decimal_place)
decimal_outcome = decimal.Decimal(str(outcome)).quantize(decimal.Decimal(rounding_string))
print(decimal_outcome)
I am expecting values like