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,675
  • 3
  • 18
  • 28
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
  • 2,630
  • 2
  • 9
  • 13