0

I want to divide

300/266336

my console responds 0 even if I do

x = 300/266336
print "%.12f" % x

the answer is 0.000000000000 I know that the answer is 0,0011263967319476 What is wrong? How to do this in console, and why does it not work in file.py?

Hiddenguy
  • 537
  • 10
  • 31
  • Possible duplicate of [How can I force division to be floating point? Division keeps rounding down to 0](https://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-division-keeps-rounding-down-to-0) – Mark Dickinson Dec 03 '17 at 09:06

2 Answers2

2

It's problem with python2. It will always give you an integer in this case. If you want to see float you have to use:

>>> float(300)/266336
0.0011263967319476151

Python 3 handles this more smoothly.

Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 300/266336
0.0011263967319476151
gonczor
  • 3,736
  • 1
  • 18
  • 40
1

... or just say 300./266336 if working with literals (dot behind 300).

Jorj McKie
  • 757
  • 6
  • 13