1

Possible Duplicate:
Why doesn't this division work in python?

A simple problem I'm having (I Think) The following statement:

    print (4950*8)/(((4950*8)/10000000*(1538/1460))+0.1/1000)/1000

Gives me 396000.0.

But on a Calculator I get 9270.614192621.

If someone could point out what I'm doing wrong in the code that would be great.

Thanks.

Community
  • 1
  • 1
Paddy
  • 195
  • 1
  • 2
  • 10

2 Answers2

5
>>> print (4950.0*8)/(((4950.0*8)/10000000*(1538.0/1460))+0.1/1000)/1000
9270.61419262
fraxel
  • 34,470
  • 11
  • 98
  • 102
4

Old versions of Python use truncated integer division for int operands.

Try from __future__ import division (see http://www.python.org/dev/peps/pep-0238/ for the full story) or coerce int operands to float (e.g. with float, or by appending .0 to literals).

ecatmur
  • 152,476
  • 27
  • 293
  • 366