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
Discussions

Float and int function
float() and int() are mainly use to convert strings to numbers. They actually create a number from the strings. int() is also often use to create an integer number from a float number. A classic example is when you ask the user for a number. The input function always returns a string of character. To perform calculation you need a number (int or float). So you must create a number from that string. As in: string_number = input("Enter temperature in °F (integer): ") temp_far = int(string_number) temp_cel = (temp_far-32) * (5/9) # the result here is a float print("Temperature in celsius (float)", temp_cel) temp_cel_int = int(temp_cel) # creates an integer number from the float print("Temperature in Celsius (integer)", temp_cel_int) Using float on strings from math import radians angle_string = input("Enter a precise angle in degrees with decimal: ") angle_float = float(angle_string) radians_float = radians(angle_float) print("That angle in degrees is",radians_float,"in radians") More on reddit.com
🌐 r/learnpython
10
5
March 25, 2023
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 int conversion - Stack Overflow
This is not a Python thing. ... While others explained why this happen I'd like to show my workaround to get floor rounding with some tolerance to floating point error nfloor = lambda x: round(x * 10**8) // 10**8 ... The int() function simply truncates the number at the decimal point, giving 250. Use ... to get 251 as an integer... More on stackoverflow.com
🌐 stackoverflow.com
How to convert float to int in program
All of the if & elifs are not necessary if stars < 1: print(movie," *") elif stars > 5: print(movie," *****") else: print(movie, "*" * stars) More on reddit.com
🌐 r/learnpython
11
1
September 18, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-float-to-int-in-python
How to convert Float to Int in Python? - GeeksforGeeks
May 10, 2025 - Let's explore different methods of doing it in Python: To convert a float value to int we make use of the built-in int() function, this function trims the values after the decimal point and returns only the integer/whole number part.
🌐
Flexiple
flexiple.com › python › float-to-int-python
How to convert Float to int in Python? | Flexiple Tutorials | Python - Flexiple
Apart from all this, when it comes to the efficiency of calculations, integer values are always preferred. This method of converting float to int in Python uses the int() method to convert float to int.
🌐
Reddit
reddit.com › r/learnpython › float and int function
r/learnpython on Reddit: Float and int function
March 25, 2023 -

Hello, please can someone explain to me when to use the float and int functions?

I mean should I use float when I am strictly dealing with decimal numbers, or when I want to convert whole numbers to decimal numbers?

pythonlearner

Top answer
1 of 4
5
float() and int() are mainly use to convert strings to numbers. They actually create a number from the strings. int() is also often use to create an integer number from a float number. A classic example is when you ask the user for a number. The input function always returns a string of character. To perform calculation you need a number (int or float). So you must create a number from that string. As in: string_number = input("Enter temperature in °F (integer): ") temp_far = int(string_number) temp_cel = (temp_far-32) * (5/9) # the result here is a float print("Temperature in celsius (float)", temp_cel) temp_cel_int = int(temp_cel) # creates an integer number from the float print("Temperature in Celsius (integer)", temp_cel_int) Using float on strings from math import radians angle_string = input("Enter a precise angle in degrees with decimal: ") angle_float = float(angle_string) radians_float = radians(angle_float) print("That angle in degrees is",radians_float,"in radians")
2 of 4
1
For string conversion, use the one appropriate to the string you're trying to convert. If you care about exact equality, don't use floats. Use integers, or maybe the Decimal class. If you want to know if floats are equal ish, keep in mind that the ish is always there. Use something like math.isclose to make such checks. There is rarely (almost never?) any need to explicitly convert integers to floats (unless you're doing something with numpy or similar). Integers will be automatically treated as floats during division (NOTE: different in some other languages), multiplication, etc. If you want to convert a float to integer, you can do that via int(2.3), but keep in mind how it rounds. There are other rounding functions that may or may not be more helpful (math.ceil, math.floor, round).
🌐
Medium
medium.com › @ryan_forrester_ › converting-floats-to-integers-in-python-a-complete-guide-9ec8c994327d
Converting Floats to Integers in Python: A Complete Guide | by ryan | Medium
November 4, 2024 - When processing sensor data or measurements, you might need to round numbers differently: def process_sensor_readings(readings, resolution=1): """ Process sensor readings with appropriate rounding. Args: readings: List of float readings resolution: Sensor resolution (minimum meaningful change) Returns: List of processed integer readings """ processed = [] for reading in readings: # First round to the sensor's resolution rounded = round(reading / resolution) * resolution # Then convert to integer if needed processed.append(int(rounded)) return processed # Example with temperature readings tempe
🌐
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().
Find elsewhere
🌐
Replit
replit.com › home › discover › how to convert a float to an int in python
How to convert a float to an int in Python | Replit
February 6, 2026 - The bin() function converts the integer to its binary string, which is prefixed with 0b. The hex() function returns the hexadecimal string representation, prefixed with 0x. This technique is common in low-level programming where you might interact directly with binary or hex values. float_number = 10.7 truncated = int(float_number // 1) negative = int(-10.7 // 1) print(truncated, negative)--OUTPUT--10 -11
🌐
Scaler
scaler.com › home › topics › convert float to int in python
Program to Convert Float to Int Python - Scaler Topics
August 22, 2023 - Integer values can be shown as such without affecting the actual data type because they are immutable. So when calculating efficiency, integer values are always preferred over floating-point values. So for all this process, we use Python inbuilt functions for converting the float value to the integer values, for example int() function, etc.
🌐
Codedamn
codedamn.com › news › python
Converting Float to Int in Python: A Step-by-Step Guide
July 3, 2023 - This function truncates the decimal part and returns the integer part of the float. float_num = 10.6 int_num = int(float_num) print(int_num) # Output: 10 · In this example, the float 10.6 is truncated to 10. When converting a float to an int in Python, it's important to note that Python does not round the number to the nearest integer; instead, it truncates it.
🌐
FavTutor
favtutor.com › blogs › float-to-int-python
Python Program to Convert Float to Int | FavTutor
February 22, 2022 - Learn how to convert float to integer in python using math.floor(), int() and NumPy library.
🌐
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.
🌐
DataCamp
datacamp.com › tutorial › python-data-type-conversion
Python Data Type Conversion: A Guide With Examples | DataCamp
February 16, 2025 - It is commonly used when the automatic (implicit) conversion provided by Python doesn’t meet your requirements. ... Note: While explicit conversions are highly useful, they can lead to information loss. For instance, converting a floating-point number to an integer will discard its fractional part.
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-floats-to-integers-in-a-pandas-dataframe
Convert Floats to Integers in a Pandas DataFrame - GeeksforGeeks
July 15, 2025 - In this example, the code begins by importing the NumPy module as 'np.' It then displays the data types of DataFrame 'df.' After that, it converts the 'Field_2' column from float to int using NumPy's int64 data type and displays the updated data types.
🌐
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
🌐
Snakify
snakify.org › integer and float numbers
Integer and float numbers - Learn Python 3 - Snakify
When we read an integer value, ... to integer using int(). When we read a floating-point number, we need to cast the string to float using float(): ... Floats with very big or very small absolute value can be written using a scientific notation. Eg., the distance from the Earth to the Sun is 1.496·1011, or 1.496e11 in Python...
🌐
Sololearn
sololearn.com › en › Discuss › 1321446 › float-to-int-python
Float to int? [python] | Sololearn: Learn to code for FREE!
I have come up with a idea like this: from itertools import count num=123.0 def toInt(num): for j in count(0): if j==num: return j elif j>10000: #just in case of potential infinite loop due to typos. break integer=toInt(num) However, this method is really inefficient, since it iterate over 0 to num.
🌐
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 - Python’s float() method will convert integers to floats. This is a quick tutorial on converting floats to integer numbers.