-1

i code for a class in spyder and i have a problem.

I cant make a variable that is a float, it makes it as a int. For ex: 1/2=0 and i have tryed to print print(float(1/2)) and it returns 0.0. And 528/298 gives me 1. Hope i can get a fast awnser.

This is for spyder, python.

Sigurd
  • 19
  • 1
  • this is not specifically spyder the editor, but python itself. Python 2.7 and earlier will not automatically convert integers to floats when performing division. Python 3.2 and later automatically converts to floats, and you can bring this behavior into 2.5(maybe a bit earlier) thru 2.7 using `from __future__ import division` – Aaron Apr 20 '17 at 14:43
  • There are many other questions that cover this exact topic like [this one](http://stackoverflow.com/questions/2958684/python-division) – Aaron Apr 20 '17 at 14:44
  • Possible duplicate of [How can I force division to be floating point? Division keeps rounding down to 0](http://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-division-keeps-rounding-down-to-0) – CDspace Apr 20 '17 at 14:49

1 Answers1

0

Assuming you're in Python 2:

from __future__ import division

gold_cy
  • 13,648
  • 3
  • 23
  • 45