To convert an integer to a float in Python you can use the following:

float_version = float(int_version)

The reason you are getting 0 is that Python 2 returns an integer if the mathematical operation (here a division) is between two integers. So while the division of 144 by 314 is 0.45~~~, Python converts this to integer and returns just the 0 by eliminating all numbers after the decimal point.

Alternatively you can convert one of the numbers in any operation to a float since an operation between a float and an integer would return a float. In your case you could write float(144)/314 or 144/float(314). Another, less generic code, is to say 144.0/314. Here 144.0 is a float so it’s the same thing.

Answer from Y2H on Stack Overflow
🌐
Manifoldapp
cuny.manifoldapp.org › read › how-to-code-in-python-3 › section › 517db09e-e5a2-4b02-bd3d-d5406a3b40a8
How To Convert Data Types | How To Code in Python 3 | Manifold @CUNY
By using the float() function, we can convert integers to floats. Python also has a built-in function to convert floats to integers: int().
Discussions

math - Safest way to convert float to integer in python? - Stack Overflow
This converts a float to an integer fairly dependably. ... What happens if you try to round a very long float? Will this at least raise an exception? 2015-05-01T00:04:53.193Z+00:00 ... @kralyk I mean a float representing a number bigger than what a normal int can hold. In Python 2, are there ... More on stackoverflow.com
🌐 stackoverflow.com
Converting large int value to float and back to int messes up the value?
There's a long-winded and very technical explanation about how floats and ints are implemented and why this happens for those numbers, but the reason why it must happen for some numbers is pretty simple: Python ints are unbounded, which means there are infinitely many ints you can have in Python. Python floats are 64-bit numbers, which means there are only 2^64 of them. Since there aren't infinitely many floats, you can't make int -> float -> int work for all numbers. The technical explanation is that ints are stored as a list of digits (essentially), so it can be as long as you want, but floats are basically a fraction, stored as a triple of numbers (s,p,q) each of a fixed-size and the numeric value of the float is (-1)^s*q*2^p. If this doesn't make sense, read up on "double-precision floating point" https://en.wikipedia.org/wiki/Double-precision_floating-point_format . The consequence of this is that floats can store very small and very large numbers, but there's a lot of gaps in between, and if your int falls in one of those gaps then when you turn it into a float with float() it picks the "nearest" one instead, so when you turn it back to an int you get the wrong value. More on reddit.com
🌐 r/learnpython
12
9
February 22, 2024
floating point - python float to in int conversion - Stack Overflow
It does not have the capability ... of a float to an int. The documentation for int can be found here: http://docs.python.org/library/functions.html#int ... >>> int(20.0) 20 >>> int('20.0') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: '20.0' You can workaround this problem by first converting to float and ... More on stackoverflow.com
🌐 stackoverflow.com
When do we use str() or float() or int() functions during programming? What is the use of changing an integer to floating point or to string?
When we parse strings from user input, from files - all the lines are usually strings. If you want to do math operations you need to convert them to internal numeric representation a = input("enter a: ") # a is str now (let's assume "1") b = input("enter b: ") # b is str now (let's assume "2") print(a+b) # will print 12 print(int(a) + int(b)) # will print 3 The opposite case, you have numeric variable but want to concatenate with string age = 25 print("Your age is " + age) # will raise an error print("Your age is " + str(age)) # will print "Your age is 25" More on reddit.com
🌐 r/learnprogramming
16
114
February 12, 2022
🌐
Python Examples
pythonexamples.org › python-convert-int-to-float
Convert Int to Float in Python - Examples
To convert integer to float in Python, we can use the float() builtin function or implicit conversion.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-integers-to-floats-in-python-3
How To Convert Integers to Floats in Python 3 | DigitalOcean
September 18, 2020 - By using the float() function, we’ve converted an integer to a float. If you’d like to learn more about converting different data types in Python, check out our How To Convert Data Types in Python 3 tutorial.
🌐
DataCamp
datacamp.com › tutorial › python-data-type-conversion
Python Data Type Conversion: A Guide With Examples | DataCamp
February 16, 2025 - You can learn more about them with DataCamp's Data Structures in Python Tutorial. Integers and floats are data types that deal with numbers. To convert an integer to a float, use the float() function in Python.
Find elsewhere
🌐
EyeHunts
tutorial.eyehunts.com › home › python convert int to float
Python convert int to float - Tutorial - By EyeHunts
February 24, 2023 - a = 5 print('Intput', a, type(a), sep='\n') #convert integer to float output = float(a) print('\nOutput', output, type(output), sep='\n') ... The Implicit conversion is the process where the Python interpreter converts the given int to float ...
🌐
Appdividend
appdividend.com › python-int-to-float
How to Convert Int to Float in Python
March 13, 2025 - Therefore, if our calculations ... and most efficient way to convert an integer to a float (double) value is using the “float()” constructor....
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › convert-int-to-float
Convert int to float - GeeksforGeeks
March 26, 2024 - Converting an integer to a floating-point number involves changing the data type of the variable from int to float, allowing decimal values. This conversion is useful when performing arithmetic operations that result in fractional values or when working with numerical data that requires precision beyond whole numbers.
🌐
LabEx
labex.io › tutorials › python-how-to-convert-between-integers-and-floats-in-python-397961
How to convert between integers and floats in Python | LabEx
When working with currency, it's often necessary to convert between integers (representing the smallest unit of currency, such as cents) and floats (representing the larger units, such as dollars). total_cents = 1273 dollars = total_cents / 100 print(dollars) ## Output: 12.73 print(int(dollars)) ## Output: 12 · Integers generally require less memory than floats, so using integers whenever possible can help optimize the memory usage of your Python applications.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-data-types-in-python-3
How To Convert Data Types in Python 3 | DigitalOcean
August 20, 2021 - By using the float() function, we can convert integers to floats. Python also has a built-in function to convert floats to integers: int().
🌐
Scaler
scaler.com › home › topics › convert float to int in python
Program to Convert Float to Int Python - Scaler Topics
August 22, 2023 - Example: Let's take a look at float values in Python ... In Python is a whole number having no decimal points. Integer values can be of any size and can be negative or positive. Int Class defines Integer values. As integer does not consist of any decimal points and hence can extend up to the computer’s limit. However, you can subsequently change it. By default, Int is decimal, or base 10, although you can later convert it.
🌐
Codedamn
codedamn.com › news › python › converting-float-to-int-in-python
Codedamn is Sunsetting
July 3, 2023 - The tools developers use, the way they learn, and the skills that matter are all shifting rapidly. Rather than retrofitting Codedamn to keep pace, our team has chosen to focus our efforts on Fermion, our white-label LMS platform built on the technology behind Codedamn.
🌐
Replit
replit.com › discover › how-to-convert-int-to-float-in-python
How to convert an int to a float in Python
February 24, 2026 - Build and deploy software collaboratively with the power of AI without spending a second on setup.
🌐
Flexiple
flexiple.com › python › float-to-int-python
How to convert Float to int in Python? | Flexiple Tutorials | Python - Flexiple
March 11, 2022 - This method of converting float to int in Python uses the int() method to convert float to int.
🌐
Quora
quora.com › How-do-I-cast-to-float-in-Python
How to cast to float in Python - Quora
Answer (1 of 2): Suppose you have an integer n, it can be converted to float either of the following ways: [code]n = 123 f0 = n + 0.0 #adding the float zero f1 = n * 1.0 #multiplying by the float unity f2 = float(n) #built-in function float() converts print(type(n)) #will print ...
🌐
Reddit
reddit.com › r/learnpython › converting large int value to float and back to int messes up the value?
r/learnpython on Reddit: Converting large int value to float and back to int messes up the value?
February 22, 2024 -

Say I have a large int value

>>> 7 ** 69
20500514515695490612229010908095867391439626248463723805607

Now let's say I convert it to a float value.

>>> float(7 ** 69)
2.050051451569549e+58

Seems about right. Now if I convert it back to back into an int...

>>> int(float(7 ** 69))
20500514515695489879650927979797501063745685669370929348608

Now it's a very different number. Why did that happen?

I am sorry if it's a stupid question but this has me very intrigued.

Top answer
1 of 11
35
There's a long-winded and very technical explanation about how floats and ints are implemented and why this happens for those numbers, but the reason why it must happen for some numbers is pretty simple: Python ints are unbounded, which means there are infinitely many ints you can have in Python. Python floats are 64-bit numbers, which means there are only 2^64 of them. Since there aren't infinitely many floats, you can't make int -> float -> int work for all numbers. The technical explanation is that ints are stored as a list of digits (essentially), so it can be as long as you want, but floats are basically a fraction, stored as a triple of numbers (s,p,q) each of a fixed-size and the numeric value of the float is (-1)^s*q*2^p. If this doesn't make sense, read up on "double-precision floating point" https://en.wikipedia.org/wiki/Double-precision_floating-point_format . The consequence of this is that floats can store very small and very large numbers, but there's a lot of gaps in between, and if your int falls in one of those gaps then when you turn it into a float with float() it picks the "nearest" one instead, so when you turn it back to an int you get the wrong value.
2 of 11
11
You've stumbled across the limitations of floating point numbers: https://docs.python.org/3/tutorial/floatingpoint.html If you look at the first 15 digits of the int and float, you'll see that the values are the same. This is because behind the scenes the float will only have 16 digits of precision due to how they are stored. Python has a library called decimals that can be used to improve precision. https://docs.python.org/3/library/decimal.html
🌐
365 Data Science
365datascience.com › blog › tutorials › python tutorials › how to convert float to int in python
How to Convert Float to Int in Python – 365 Data Science
April 21, 2023 - We can perform something called “casting a floating-point number to an integer” to convert our data types. Essentially, it’s transforming a float to an int in Python.