Floor division with negative number

后端 未结 4 2261
夕颜
夕颜 2020-11-27 22:14

The expression 6 // 4 yields 1, where floor division produces the whole number after dividing a number.

But with a negative number, why do

4条回答
  •  Happy的楠姐
    2020-11-27 22:41

    Floor division will also round down to the next lowest number, not the next lowest absolute value.

    6 // 4 = 1.5, which rounds down to 1, and up to 2.

    -6 // 4 = -1.5, which rounds down to -2, and up to -1.

提交回复
热议问题