Quick answer: In GDScript, dividing an int by an int gives an int: 5 / 2 is 2, and 35 / 100 is 0. The warning marks every place where that happens. If you wanted the fraction, make one operand a float (float(hp) / max_hp or hp / 2.0). If you wanted a whole number, keep the code and put @warning_ignore("integer_division") on the line above.

This is a warning, so the script still runs. Whether it matters depends on what you meant. A health bar that stays empty until the player is at full health, a percentage that is always 0, an average that is slightly too low: these are the bugs it is pointing at. An index turned into a row and a column, or seconds turned into minutes, are cases where discarding the remainder is the whole point. This guide covers the exact wording per Godot version, how GDScript decides the result type, the fix for each intent, what happens with negative numbers, and the separate division by zero error.

The exact warning

Godot 3 and Godot 4.0 through 4.4 print:

Integer division, decimal part will be discarded.

Godot 4.5 and later changed the punctuation:

Integer division. Decimal part will be discarded.

In the script editor it appears in the warnings list under the code (click the warning count at the bottom of the script editor to open it), prefixed with the line and the warning code:

Line 14 (INTEGER_DIVISION): Integer division, decimal part will be discarded.

The same warning is listed in the Debugger panel when the script loads in a running game. If someone has raised the warning level to Error in the project settings, the line stops the script from loading and the text ends with (Warning treated as error.)

How GDScript picks the result type

The / operator looks at the types of its two operands. Two integers give an integer, and the fractional part is cut off. If either side is a float, the result is a float. GDScript has no separate integer division operator such as //, so the operand types are the only switch.

ExpressionResultWhy
5 / 22int / int
5 / 2.02.5One float operand is enough
float(5) / 22.5Converted before dividing
5 * 1.0 / 22.5Evaluated left to right: 5.0 / 2
5 / 2 * 1.02.0The division already happened as int
35 / 100 * 100035 / 100 is 0
35 * 100 / 10035Multiply first, then divide
1 / 3 * 301 / 3 is 0
-7 / 2-3Cut toward zero, not rounded down
floori(-7 / 2.0)-4Rounded down
7 % 2, -7 % 21, -1The remainder keeps the sign of the left operand
posmod(-7, 2)1Remainder that is never negative
Vector2i(7, 5) / 2Vector2i(3, 2)Integer vectors follow the same rule
Vector2i(7, 5) / 2.0Vector2(3.5, 2.5)A float divisor gives a float vector
5.0 / 0infFloat division by zero is not an error
5 / 0ErrorSee division by zero

The type of the variable you store the result in does not change this. var ratio: float = hp / max_hp divides two integers, gets 0, and then converts that 0 to 0.0.

Where it turns into a bug

  1. Ratios between 0 and 1. hp / max_hp, loaded / total, elapsed_frames / duration_frames. With integers the result is 0 for every value below the maximum and 1 at the maximum, so a bar or a fade jumps from empty to full.
  2. Percentages written as divide, then multiply. kills / shots * 100 is 0 unless every shot hit. The order matters: kills * 100 / shots gives a whole-number percentage.
  3. Averages. total_score / rounds with a total of 7 over 2 rounds is 3, not 3.5.
  4. Halving and scaling. damage / 2 turns 5 into 2, and speed * (level / 10) multiplies by 0 for levels 1 to 9.
  5. Grid coordinates. int(position.x) / 16 is correct for positive positions and wrong for negative ones. That case is in the section on negative numbers.

The health bar version is the one most people meet first:

var hp: int = 35
var max_hp: int = 100

func update_bar() -> void:
    $HealthBar.value = hp / max_hp * 100    # 0 until hp reaches max_hp

When Godot warns and when it stays quiet

The warning is raised while the script is parsed, and only when Godot knows at that point that both operands are integers. That has three consequences.

Untyped values get no warning and the same result. A function parameter without a type, a value read from a Dictionary, or a property read through a variable typed as Node has no known type while parsing, so there is nothing to warn about. If both values turn out to be integers when the line runs, the division is still an integer division.

func ratio(current, maximum):
    return current / maximum     # no warning; ratio(35, 100) still returns 0

The compound operator is not checked. hp /= 2 with an integer hp truncates in the same way and produces no warning in any Godot 4 version up to 4.6.

Integer vectors are covered from Godot 4.6. That version also raises the warning for a Vector2i, Vector3i or Vector4i divided by an int or by a vector of the same type. Earlier versions truncate those without comment.

So a clean warnings list does not prove a formula is right. If a ratio matters, type its inputs (see the guide to := and type inference) or convert explicitly as shown next.

Fix 1: you wanted the fraction

Make at least one operand a float before the division happens. Any of these works:

var hp: int = 35
var max_hp: int = 100

func update_bar() -> void:
    var ratio := float(hp) / max_hp            # 0.35, convert a variable
    var half := hp / 2.0                       # 17.5, write the literal as a float
    $HealthBar.value = ratio * 100.0           # 35.0
    print(half)

Which one to use:

After switching to float you may get the opposite warning when the result goes into an integer variable: Narrowing conversion (float is converted to int and loses precision). Say which rounding you want with int() (cut toward zero), floori(), ceili() or roundi().

Fix 2: you wanted a whole number

Integer division is the right tool for splitting an index into rows and columns, converting seconds to minutes, or counting how many full stacks fit in an inventory. Keep the code and tell Godot the truncation is deliberate with an annotation on the line above the statement:

func format_time(total_seconds: int) -> String:
    @warning_ignore("integer_division")
    var minutes := total_seconds / 60
    var seconds := total_seconds % 60
    return "%d:%02d" % [minutes, seconds]

func slot_to_cell(index: int, columns: int) -> Vector2i:
    @warning_ignore("integer_division")
    var row := index / columns
    return Vector2i(index % columns, row)

The [Ignore] link next to the warning in the script editor’s warnings list inserts that annotation for you. It applies to the one statement that follows it. Other ways to silence it:

ScopeHowVersions
One statement@warning_ignore("integer_division") on the line aboveGodot 4.0 and later
A region of a file@warning_ignore_start("integer_division") before, @warning_ignore_restore("integer_division") afterGodot 4.4 and later
One statement, Godot 3The comment # warning-ignore:integer_division on the line aboveGodot 3
The whole projectProject > Project Settings > Debug > GDScript > Integer Division, set to Ignore (turn on Advanced Settings if the section is hidden)Godot 4

Prefer the per-statement annotation. Turning the warning off for the project also hides the next health bar bug. The same setting accepts Error, which makes every unannotated integer division stop the script from loading; some teams use that to force a decision at each site.

Negative numbers: truncation is not floor

Integer division cuts toward zero. For positive numbers that is the same as rounding down. For negative numbers it rounds up: -7 / 2 is -3, while the floor of -3.5 is -4. Code that maps positions to grid cells shows the difference as soon as something moves left of or above the origin:

const CELL := 16

func world_to_cell(pos: Vector2) -> Vector2i:
    # Wrong for negative positions: x = -8 and x = 8 both land in column 0
    # return Vector2i(int(pos.x) / CELL, int(pos.y) / CELL)
    return Vector2i(floori(pos.x / CELL), floori(pos.y / CELL))

pos.x / CELL is a float division because pos.x is a float, and floori() rounds it down to an int. For two integers, write floori(a / float(b)). If the grid is a TileMapLayer or TileMap node, its local_to_map() method does this for you.

The remainder operator has the matching behavior. % works on integers only and its result takes the sign of the left operand, so stepping backward through a list with (index - 1) % count gives -1 at index 0. Use posmod(index - 1, count) or wrapi(index - 1, 0, count), which stay in the range 0 to count - 1. For floats, % is a parse error (Invalid operands "float" and "int" for "%" operator.); use fmod(), or fposmod() for the version that is never negative.

Division by zero is a different error

The warning says nothing about the divisor being zero. That is a separate runtime error, and only integer types have it:

Division by zero error in operator '/'.

A debug build reports it on the line that divides, and when you run from the editor the debugger stops there. When both operands are constants, as in var x = 10 / 0, Godot reports it while parsing as Division by zero error in operator /. The remainder operator has its own version, Modulo by zero error in operator '%'.

Two things follow from this. Converting to float to fix the warning also removes the error: float(hp) / max_hp with max_hp at 0 quietly produces inf or nan, which then travels into a progress bar or a position. And release export templates are built without the runtime check, so an integer division by zero there can end the process outright. Guard the divisor in both cases:

func hp_ratio(hp: int, max_hp: int) -> float:
    if max_hp <= 0:
        return 0.0
    return float(hp) / max_hp

How to confirm the fix

Save the script and open the warnings list: the INTEGER_DIVISION entry for that line is gone. Then check the number, since the warning disappearing only proves the types changed. Print the value for three inputs: one below the maximum, one at it, and zero. A ratio should read something like 0.35, 1.0 and 0.0. For grid code, test a negative coordinate. Finally use Search > Find in Files for /= and for divisions inside untyped functions, because those are the integer divisions Godot does not flag.

What reaches players

The warning exists only in the editor, and Bugnet has no part in it. The bug it describes is also invisible to automatic capture: a health bar stuck at empty or an average that is slightly off raises no error anywhere. That kind reaches you when a player notices and files it. With Bugnet’s Godot SDK in the build, the in-game report form attaches the platform, OS and game version, and a screenshot when screenshot capture is on for the project, which for a bar showing the wrong value is most of the evidence you need.

Division by zero is different because the engine logs it. The SDK’s automatic capture reads the engine’s log file, so in a debug build with File Logging enabled (it is off by default on mobile exports) the error can arrive as a report, stacked with other occurrences of the same title. In a release build the check is absent, and if the process dies, nothing is reported: Bugnet does not capture native crashes. The guard above is the dependable route, and the branch that should never run is a good place for Bugnet.report_error("max_hp is zero", "hp_ratio() in player.gd"). The report fields are listed in the bug report docs.

Frequently asked questions

What does Integer division, decimal part will be discarded mean in Godot?

Both sides of a / are integers, so GDScript returns an integer and drops the fraction: 5 / 2 is 2 and 35 / 100 is 0. It is the INTEGER_DIVISION warning and the script still runs. It only matters if you expected a fractional result.

How do I get a float from dividing two integers in GDScript?

Convert one operand before dividing, for example float(a) / b, or write a literal divisor as a float such as a / 2.0. Converting the result, as in float(a / b), is too late because the fraction is already gone. Storing the result in a float variable does not help either.

How do I disable the integer division warning in Godot 4?

Put @warning_ignore("integer_division") on the line above the statement, or click the Ignore link next to the warning in the script editor. To change it for the whole project, set Integer Division under Project Settings > Debug > GDScript to Ignore. Godot 3 uses the comment # warning-ignore:integer_division instead.

Why is my health bar always 0 or full in Godot?

The bar is fed hp / max_hp with two integer variables, which is 0 for every value below the maximum and 1 at the maximum. Use float(hp) / max_hp to get a ratio between 0 and 1. For a whole-number percentage, multiply first: hp * 100 / max_hp.

Does integer division round down in GDScript?

It truncates toward zero, which matches rounding down only for positive results. -7 / 2 is -3, while rounding down would give -4. Use floori(a / float(b)) when you need floor behavior, for example when converting negative positions to grid cells.

int / int is an int in GDScript. Convert one operand with float() when you want the fraction, and annotate the line with @warning_ignore when the whole number is what you meant.