“Implicit conversion from float … to int loses precision”: what it means in WordPress, and the fix
Short answer
It’s a deprecation notice from PHP 8.1 and later: a plugin or theme uses a number with decimals, like 1.5, where PHP needs a whole number, such as a list size, a count or an array key. PHP cuts off the decimals, as it always did, and the page keeps working; since 8.1 it also tells you that something was lost. With a number stored as text, like a rating "4.5", the message says float-string. Update the plugin or theme; the developer fix is to round on purpose, with round(), floor() or ceil().
The message, exactly
A product grid splits 3 products into rows of 3 / 2 products, which is 1.5, and prints a rating saved as the text 4.5 as stars. PHP 8.0 says nothing; PHP 8.1 adds two notices, with the same output:
wp-content/plugins/product-grid/product-grid.php
<?php
$products = ['Mug', 'Cap', 'Pen'];
$per_row = count($products) / 2; // 1.5
$rows = array_chunk($products, $per_row);
echo count($rows), " rows\n";
$rating = '4.5'; // a rating saved as text
echo str_repeat('*', $rating), "\n";
3 rows
****Deprecated: Implicit conversion from float 1.5 to int loses precision in /var/www/html/wp-content/plugins/product-grid/product-grid.php on line 4
3 rows
Deprecated: Implicit conversion from float-string "4.5" to int loses precision in /var/www/html/wp-content/plugins/product-grid/product-grid.php on line 8
****On both versions the grid has 3 rows of 1, not rows of 2, and the rating shows 4 stars, not 4.5 or 5. PHP cut the decimals before 8.1 too; now it says so.
php.net, in the PHP 8.1 deprecations: “The implicit conversion of float to int which leads to a loss in precision is now deprecated.” (php.net) It names the places affected: array keys, int parameters of functions (when strict types are off), and operators that work on whole numbers.
What it means
Some places in PHP need a whole number: how many items per chunk, how many times to repeat, which position in a list. When the code passes 1.5, PHP has to drop the .5. That was always silent; PHP 8.1 made it a deprecation notice so the code’s author can decide what should happen instead.
The number in the message is the value at that moment. It may differ from visit to visit; the file and line don’t.
Is it urgent?
No. Nothing changes on the page because of the notice. Two reasons to pass it on anyway: the result may not be what the plugin meant (4 stars for a 4.5 rating), and the notices fill the log on every visit. Meanwhile, keep PHP messages off your pages: the WordPress debug log.
Who fixes it
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates).
- Still there? Send the full message to its developer, with the page where it happens.
Can a check find it before the upgrade?
Not by reading code: array_chunk( $products, $per_row ) is fine when $per_row is 2 and only loses precision when it’s 1.5. We ran CompatNav’s scanner on the example above: no finding, as expected. Your error log after the move to PHP 8.1 is the place to look; checking it for a few days catches these early. Other value-dependent PHP 8.1 notices: “Passing null to parameter … is deprecated” and “Automatic conversion of false to array is deprecated”.
Key takeaways
- A deprecation notice from PHP 8.1 and later; the code keeps working exactly as before.
- PHP has always cut 1.5 down to 1 in these places; the notice just makes the loss visible.
- “float-string” means the number was stored as text, like a rating saved as 4.5.
- It depends on the values at run time, so only the error log shows it, not a code check.
- The developer fix: decide how to round (
round(),floor(),ceil()) and cast with(int).
Frequently asked questions
Does this break my site?
No. PHP does exactly what it did on PHP 8.0: it drops the decimals and carries on. The notice only goes to the log, or to your pages if your host displays PHP messages.
Is the result wrong?
It can be: in our test, a rating of 4.5 printed 4 stars on PHP 8.0 and 8.1 alike. The notice is PHP pointing at a place where the code may not do what its author meant.
Why do I see a number like 13.35 in the message?
That’s the value at that moment, so the message changes from page to page. The file and line stay the same: that’s what to send to the developer.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.