Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

How to Convert a Float to an Integer in Python

Python’s int() converts a float by truncating toward zero—not rounding. Learn when to use int(), math.floor(), math.ceil(), round(), or Decimal.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.