"Deprecated: Implicit conversion from float to int loses precision" in PHP — What It Means and How to Fix It

What the PHP error "Deprecated: Implicit conversion from float to int loses precision" means and how to fix it.

Published November 1, 2026

PHP 8.1 deprecated silently converting a float with a fractional part to an integer, because the decimals are discarded. The notice tells you to make the conversion explicit.

What it means and why it happens

It appears when a float is used as an array key, in bitwise or modulo operations or passed to an int parameter, for example $arr[3.7] or 10.5 % 3.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Deprecated: Implicit conversion from float 3.7 to int loses precision in app.php on line 8

Practical examples

Code that triggers it

<?php
$arr = [1, 2, 3, 4];
$i = 7 / 2;          // 3.5
echo $arr[$i];       // implicit float to int

The fix

<?php
$i = intdiv(7, 2);          // 3, integer division
// or be explicit about rounding:
$i = (int) floor(7 / 2);
echo $arr[$i];

Choose the rounding you mean

(int) 3.7;      // 3  truncates
floor(3.7);     // 3
ceil(3.7);      // 4
round(3.7);     // 4

Common mistakes

  • Silencing the notice instead of deciding how to round.
  • Using floats as array keys.
  • Using / when integer division (intdiv or %) is intended.

Key takeaways

  • Implicit conversion from float to int loses precision: PHP 8.1 deprecated silently converting a float with a fractional part to an integer, because the decimals are discarded.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Is it an error?

It is a deprecation: code still runs in 8.1+, but future versions may make it an error.

How do I find which line caused Implicit conversion from float to int loses precision?

The error message and stack trace show the file and line; start there and work backwards.

More PHP articles