All integers that can be represented by floating point numbers have an exact representation. So you can safely use int on the result. Inexact representations occur only if you are trying to represent a rational number with a denominator that is not a power of two.

That this works is not trivial at all! It's a property of the IEEE floating point representation that int∘floor = ⌊⋅⌋ if the magnitude of the numbers in question is small enough, but different representations are possible where int(floor(2.3)) might be 1.

To quote from Wikipedia,

Any integer with absolute value less than or equal to 224 can be exactly represented in the single precision format, and any integer with absolute value less than or equal to 253 can be exactly represented in the double precision format.

Answer from Philipp on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-float-to-int-in-python
How to convert Float to Int in Python? - GeeksforGeeks
May 10, 2025 - 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.
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
Python: Convert float to int in numpy array
I’m trying to convert floats to integer in python and store the integer in a string, but I’m still getting the string with float values. Can anyone please help me to understand, how I can convert float to int and store the int value in the string? Code having issue: _number_of_alphabets, ... More on discuss.python.org
🌐 discuss.python.org
1
0
February 16, 2022
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
floating point - Python float to int conversion - Stack Overflow
Basically, I'm converting a float to an int, but I don't always have the expected value. Here's the code I'm executing: x = 2.51 print("--------- 251.0") y = 251.0 print(y) print(int(y)) print( More on stackoverflow.com
🌐 stackoverflow.com
🌐
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().
🌐
Scaler
scaler.com › home › topics › convert float to int in python
Program to Convert Float to Int Python - Scaler Topics
August 22, 2023 - Using the round() method, a float value can be converted to an int value, which is the closest integer value. When there is an equal difference between smaller and larger values, the larger integer is chosen. ... Return Value: This method returns an integer value rounding the given value to ...
🌐
DataCamp
datacamp.com › tutorial › python-data-type-conversion
Python Data Type Conversion: A Guide With Examples | DataCamp
February 16, 2025 - Data conversion in Python can happen in two ways: either you explicitly tell the compiler to convert a data type to some other type, or the compiler understands this by itself and does it for you. In the former case, you're performing an explicit data type conversion, whereas, in the latter, you're doing an implicit data type conversion. Implicit conversion or coercion is when data type conversion takes place either during compilation or during run time and is handled directly by Python for you. Let's see an example: a_int = 1 b_float = 1.0 c_sum = a_int + b_float print(c_sum) print(type(c_sum))
🌐
Python Guides
pythonguides.com › convert-float-to-int-python
How to Convert Float to Int in Python?
March 20, 2025 - The int() function truncates the decimal part and returns only the integer portion of the float. This means it always rounds toward zero, discarding any decimal values. Check out How to Read Tab-Delimited Files in Python? Sometimes simply truncating a float isn’t what you want. Python offers several ways to round numbers before converting them to integers.
🌐
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).
Find elsewhere
🌐
DEV Community
dev.to › mathewchan › python-syntax-learning-1-convert-float-to-int-1587
Python syntax learning 1: Convert float to int - DEV Community
June 3, 2022 - import math num2 = 5.9 int2 = math.floor(num2) print(int2) num3 = 5.1 int3 = math.floor(num3) print(int3)
🌐
Altcademy
altcademy.com › blog › how-to-convert-float-to-int-in-python
How to convert float to int in Python - Altcademy.com
September 7, 2023 - In this code, round(x) rounds the float x to the nearest whole number (4 in this case), and then int() converts that rounded float to an integer. It's like if you're 3.99 steps up a staircase, rounding would say you're closer to the 4th step ...
🌐
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.
🌐
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.
🌐
YouTube
youtube.com › watch
How To Turn Float Into Int Python - YouTube
In this python tutorial, we answer the question of how to turn float into int python. We show you 2 different methods on how to convert a float type into an ...
Published: January 18, 2021
🌐
Python.org
discuss.python.org › python help
Python: Convert float to int in numpy array - Python Help - Discussions on Python.org
February 16, 2022 - I’m trying to convert floats to integer in python and store the integer in a string, but I’m still getting the string with float values. Can anyone please help me to understand, how I can convert float to int and store the int value in the string? Code having issue: _number_of_alphabets, _number_of_numbers, _number_of_special_characters = ranges(_size,_number_of_alphabets,_number_of_numbers,_number_of_special_characters) _list = alphabets(_number_of_alphabets) _list = append(_lis...
🌐
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 › how to convert float to int in program
r/learnpython on Reddit: How to convert float to int in program
September 18, 2023 -

I created this program and was wondering that if someone were to input a decimal (ex: 1.5) for a rating, it would round down to 1 and show the correct number of starts. here's my code.

movie = input("Enter a movie: ")
stars = int(input("Rate between 1 and 5: "))

if stars == 1:
print(movie," *")
elif stars == 2:
print(movie," **")
elif stars == 3:
print(movie," ***")
elif stars == 4:
print(movie," ****")
elif stars == 5:
print(movie," *****")
if stars < 1:
print(movie," *")
elif stars > 5:
print(movie," *****")

🌐
Python Tutorial
pythontutorial.net › home › advanced python › python float to int
How To Convert a Float to an Int in Python
February 20, 2021 - In this tutorial, you'll learn how to convert a float to an integer using the truncation, floor, ceiling functions.
🌐
YouTube
youtube.com › watch
How To Convert Float To Int In Python - YouTube
This video teaches how to convert float to int in Python. To convert a float to an integer in Python, you need to use the int constructor method.#pythontutor...
Published: March 30, 2023
🌐
Replit
replit.com › home › discover › how to convert an int to a string in python
How to convert an int to a string in Python | Replit
April 14, 2026 - The expression f"${total:.2f}" tells Python to format the total variable as a floating-point number with exactly two decimal places. This technique is essential for displaying currency or any other values where precision matters. It ensures your output is clean and easy to read, avoiding the long trail of decimals that raw float calculations can create. When you're converting user input to a number, you can't always trust what you'll get. The int() function will crash your program with a ValueError if the input isn't a valid integer.
🌐
Stack Overflow
stackoverflow.com › questions › 6569528 › python-float-to-int-conversion
floating point - Python float to int conversion - Stack Overflow
Basically, I'm converting a float to an int, but I don't always have the expected value. Here's the code I'm executing: x = 2.51 print("--------- 251.0") y = 251.0 print(y) print(int(y)) print(...