Skip to content
Advertisement

Behaviour of ROUND_HALF_DOWN , Python 3.9.5, decimal module

OS: fedora 34 workstation, GNU/Linux

I am confused. In the decimal module documentation section “Rounding modes” says,

JavaScript

I have an example

JavaScript

I was expecting as result 25.25 because the sum results in n1 = 25.2555 has a 5 in the thousandths position, then must go DOWN to 0 and the hundredths position remain the same.

Am I wrong?

why I am getting there 25.26?

enter image description here enter image description here

Advertisement

Answer

It says:

Round to nearest with ties going towards zero.

In this particular case there isn’t a tie because 25.2555 is closer to 25.26 than it is to 25.25. So it just rounds to the nearest, which is 25.26.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement