October 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 PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How a Single int() Call Can Silently Disable a Risk Check

A call to int() on a float discards the fractional part without any error. Here is how that silently changes threshold decisions and how to prevent it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A call to int() on a float does not raise an error when it drops the fractional part. It returns a different whole number, and if that number feeds a risk threshold, the rule can pass or fail on values it was never meant to judge. The failure is silent because nothing in the program signals that a fraction was discarded. This article explains exactly what the conversion does, how it turns into a missed control, and how to close the gap before a limit goes live.

What int() does to a float

Python’s built-in types documentation states: “Conversion from float to int truncates, discarding the fractional part.” Truncation means the value moves toward zero. That is different from rounding to the nearest integer and different from flooring, and the difference matters most for negative numbers.

As an Amazon Associate I earn from qualifying purchases.

Input int(x) round(x) math.floor(x)
99.9 99 100 99
100.4 100 100 100
-0.5 0 0 -1
-1.7 -1 -2 -2

The first column is the one a conversion produces. None of the other columns is “more correct” in general. Each encodes a different policy, and int() implements only the truncation policy, whether or not your rule asked for it.

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

How a threshold quietly changes its answer

Consider a rule that blocks exposure above a cap of 499 units. The check looks reasonable:

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.
MAX_EXPOSURE = 499

def exposure_ok(exposure):
    return not (int(exposure) > MAX_EXPOSURE)

print(exposure_ok(499.99))   # True: the rule passes it
print(int(499.99))           # 499

The true exposure is 0.99 units over the cap. After truncation it equals the cap, so the strict comparison never fires. Nothing was rejected, logged, or flagged. The control simply did not see the value it was written to catch.

Float arithmetic adds a second source of error before the conversion even runs. Binary floating point cannot represent 0.29 exactly, and multiplying by 100 can land just below the intended integer:

print(0.29 * 100)        # 28.999999999999996
print(int(0.29 * 100))   # 28

A rule that expects 29 cents now sees 28. Both errors come from the same place: the value was converted to an integer without anyone deciding what should happen to the fraction.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

A documented payment example

In Python issue 27697, opened on 2016-08-05, the issue author Nathan Snobelen reported: “We have some payment code which formats numbers for processing in our system and we noticed that the payment of 1108431.38 was dropped by a penny to 1108431.37.” That is a historical report about one payment path. It shows the mechanism clearly, but it is not evidence of how any particular production system behaves today, and it does not establish that every multiplication by 100 loses a cent.

Why the failure stays hidden

  • No exception is raised. int() returns a valid integer, so type checks and input validation pass.
  • No fraction is recorded. The discarded digits do not appear in logs unless the code logs the original value.
  • Only boundary values are affected. Most amounts behave correctly in testing, so the defect surfaces only near a limit, which is exactly where risk rules matter most.
  • Negative values behave differently. A value such as -0.5 becomes 0, which can pass a check written for negative exposures.

Decide the rule before you convert

Write down what the threshold should do with a fractional input. The usual options are an exact decimal comparison, rounding to nearest, flooring, or rejecting non-integral input. int() is only correct when truncation is the policy you actually want.

  1. State the rule in one sentence, including how fractions are handled and which boundary is inclusive.
  2. Validate before conversion. For floats, reject or flag values that are not whole numbers:
    def require_whole(value):
        if not float(value).is_integer():
            raise ValueError(f'non-integral input: {value!r}')
        return int(value)
  3. Log the original value next to the converted value at every decision point, so a discarded fraction can be seen after the fact.
  4. Test values on both sides of each boundary, including negative values if your domain allows them.

Represent money with Decimal built from strings

For currency and other decimal quantities, construct Decimal from a string or from already-validated decimal input rather than passing a float through the conversion chain:

Rank #3
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
from decimal import Decimal

amount = Decimal('1108431.38')
cents = amount * 100          # Decimal('110843138.00')
print(int(cents))             # 110843138

Multiplication and conversion stay exact here because the value never passed through binary floating point.

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

Decimal(3.14) is not Decimal(‘3.14’)

The Python decimal documentation distinguishes the two forms. Decimal('3.14') represents the decimal value you typed. Decimal(3.14) captures the binary float that is already the nearest approximation, which carries many more digits:

from decimal import Decimal

print(Decimal('3.14'))
# 3.14
print(Decimal(3.14))
# 3.140000000000000124344978758017532527446746826171875

If the source data arrives as text, parse it as text. If it arrives as a float, the precision is already gone before your code sees it.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Make inexact rounding visible

Decimal contexts can turn silent rounding into an error. Setting the Inexact and Rounded traps makes an operation raise when it loses digits:

from decimal import Decimal, Inexact, Rounded, localcontext

with localcontext() as ctx:
    ctx.traps[Inexact] = True
    ctx.traps[Rounded] = True
    Decimal('1.005').quantize(Decimal('0.01'))   # raises decimal.Inexact

Use this in code paths where a silently rounded value would change a decision. Leave it off where rounding is the intended policy and has been specified.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

The digit limit is a different problem

CPython also limits conversions between very long decimal strings and integers. The CPython security FAQ for CVE-2020-10735 explains that the limit exists to prevent excessive CPU use when untrusted input is parsed with int() or converted back to a string. That is a denial-of-service safeguard. It has nothing to do with losing a fractional part, and it is not a fix for a truncated risk value. Do not disable it as a remedy for a threshold bug.

Check conversions at library and C boundaries

Implicit integer conversion can also happen inside extension code. Python issue tracker issue 36048, opened on 2019-02-20, documents C integer conversion paths that used __int__ and could truncate non-integral Decimal or Fraction values. That discussion is historical, and the handling has changed across versions, so confirm the behavior of the Python version you deploy before relying on it either way.

Checklist before a threshold ships

  • The rule states how fractional values are treated, and the code implements that rule explicitly.
  • Money and other decimal quantities are parsed from strings into Decimal, not from floats.
  • Every int() call in a decision path has a validation step or a documented reason for truncation.
  • Decision logs record the original value and the converted value.
  • Boundary tests cover values just below, at, and just above each limit, including negative inputs where valid.
  • The deployed Python version has been checked against the behavior you are relying on.

“””

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.