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
  • 547
  • 13
  • 33
  • 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,994
  • 1
  • 21
  • 46
1

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

Jorj McKie
  • 2,062
  • 1
  • 13
  • 17