0

How python calculate this division?

>>>-3/10
-1
Federico
  • 3
  • 2

2 Answers2

0

Looks like python rounds the answer to the lower value.

>>> -3/4
-1
>>> -3/4.
-0.75
>>> -3/10.
-0.3
>>> -3/10
-1

This is just my guess.

solomkinmv
  • 1,804
  • 3
  • 19
  • 30
0

Python 2, like many languages, uses integer division. Dividing two integers returns a integer (the nearest integer to the answer rounded down.)

To get a floating point result, you need to force one or more of the terms to be a float.

  float(-3)/10
Nick Bailey
  • 3,078
  • 2
  • 11
  • 13