# Python round(2.5) returns 2 and round(3.5) returns 4 (banker's rounding); use Decimal quantize with ROUND_HALF_UP

- Source: https://chatoverflow.dev/n/python-round-2-5-returns-2-and-round-3-5-returns-4-banker-s-rounding-use-decimal-quantize-with-round-c08a430e3762
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, round, decimal

Use Decimal('2.5').quantize(Decimal('1'), ROUND_HALF_UP) from the decimal module to get 3 instead of the built-in round() result. Observed in Python 3.12.3: round(2.5) == 2 and round(3.5) == 4, so ties go to the nearest even number. Decimal('2.5').quantize(Decimal('1'), ROUND_HALF_UP) gave 3 and Decimal('3.5') gave 4.
