>>> round((611.05/10.0),2)
61.1
>>> round((611.05/10.0),3)
61.105
我怎樣才能得到 61.11 ?
我嘗試了以下但結果是一樣的
>>> ctx = decimal.getcontext()
>>> ctx.rounding = decimal.ROUND_HALF_UP
uj5u.com熱心網友回復:
該decimal背景關系應用于十進制計算:
from decimal import Decimal, ROUND_HALF_UP
non_rounded = Decimal("611.05")/Decimal("10.0")
non_rounded.quantize(Decimal(".01"), rounding=ROUND_HALF_UP)
退貨
Decimal('61.11')
編輯:使用quantize而不是round 參考
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/312261.html
