Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RoundingMode

Seven rounding modes are available:

ConstantDescription
ROUND_DOWNTruncate toward zero
ROUND_UPRound away from zero
ROUND_HALF_UPRound half away from zero (traditional)
ROUND_HALF_DOWNRound half toward zero
ROUND_HALF_EVENBanker’s rounding (default)
ROUND_CEILINGRound toward +∞
ROUND_FLOORRound toward −∞
var x = Decimal("2.5")
print(x.round(0, ROUND_HALF_UP))    # 3
print(x.round(0, ROUND_HALF_EVEN))  # 2  (banker's rounding)
print(x.round(0, ROUND_DOWN))       # 2
print(x.round(0, ROUND_UP))         # 3
print(x.round(0, ROUND_CEILING))    # 3
print(x.round(0, ROUND_FLOOR))      # 2