Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Use Python’s built-in int() function to convert a float to an integer. It truncates the fractional part toward zero: int(3.9) returns 3, while int(-3.9) returns -3. It does not round to the nearest integer.
Convert a float with int()
Pass the float to int() and assign the returned integer wherever you need it:
value = 3.9
whole = int(value)
print(whole) # 3
The fractional part is discarded by truncating toward zero. For a negative value, that means the result moves toward zero rather than toward the next lower integer:
int(-3.9) # -3
Python’s documentation for Python 3.13.16 built-in functions explicitly describes float conversion this way.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →#1 Best Overall
Choose truncation, floor, ceiling, or rounding
These operations can produce different integers, especially for negative values. For -3.9, their results are:
| Intended result | Python expression | Result |
|---|---|---|
| Discard the fraction toward zero | int(x) or math.trunc(x) |
-3 |
| Greatest integer less than or equal to x | math.floor(x) |
-4 |
| Least integer greater than or equal to x | math.ceil(x) |
-3 |
| Nearest integer | round(x) |
-4 |
Use int() or math.trunc() when you mean truncation; use math.floor() or math.ceil() when you need a specific direction at an integer boundary. Use round() when the goal is the nearest integer. Python’s built-in type reference documents these operations separately and specifies ties-to-even behavior for round(); see the numeric types reference. The math documentation describes math.trunc() as truncating toward zero.
Rank #2
import math
x = -3.9
int(x) # -3
math.trunc(x) # -3
math.floor(x) # -4
math.ceil(x) # -3
round(x) # -4
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Why a decimal-looking float can convert unexpectedly
Python stores floats as binary floating-point values, so many decimal fractions cannot be represented exactly. Conversion operates on the actual float value Python holds, not on the decimal text you may expect it to represent. The floating-point arithmetic tutorial explains this representation behavior.
If exact decimal arithmetic matters—for example, when applying a defined rounding rule to decimal quantities—consider decimal.Decimal and choose an explicit integral conversion or rounding operation. The Decimal documentation covers to_integral_value() and related methods. Like the built-in round(), round(Decimal_value) without an ndigits argument returns the nearest integer with ties to even.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




