Runde Python -Dezimalheit auf die nächste 0,05Python

Python-Programme
Anonymous
 Runde Python -Dezimalheit auf die nächste 0,05

Post by Anonymous »

Ich versuche, Geldzahlen in Dezimalzahlen auf die nächste 0,05 zu runden. Im Moment mache ich das: < /p>

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

def round_up(amount):
amount = int(math.ceil(float(100 * amount) / 5)) * 5 / Decimal(100)
return Decimal(amount)
< /code>

Gibt es eine Möglichkeit, dies eleganter zu machen, ohne mit Python -Dezimalstellen umzugehen (vielleicht mit Quantize)? < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post