خرید بک لینک

Vote count: 0

I'm trying to round money numbers in Decimal to the nearest 0.05. Right now, I'm doing this:

def round_down(amount):
    amount *= 100
    amount = (amount - amount % 5) / Decimal(100)
    retu Decimal(amount)

def round_up(amount):
    amount = int(math.ceil(float(100 * amount) / 5)) * 5 / Decimal(100)
    retu Decimal(amount)

Is there any way I can do this more elegantly without dealing with floats using python Decimals (using quantize perhaps)?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 26 خرداد 1395 ساعت: 11:18

صفحه بندی