Jump to content

PHP Deprecated: Implicit conversion from float 1.15 to int loses precision


bobl61

Recommended Posts

PHP Deprecated:  Implicit conversion from float 0.1322222222222222 to int loses precision in sig.php on line 407, referer: hlstats.php?mode=playerinfo&player=1

PHP Deprecated:  Implicit conversion from float 1.15 to int loses precision in sig.php on line 410, referer: hlstats.php?mode=playerinfo&player=8

line 407 $hours       += floor($timestamp / 3600 % 24);

line 410 $min         = floor($timestamp / 60 % 60);




Program is HlstatX. Server: XAMPP 8.2.4 (PHP 8.2.4). OS Windows 11

sig.txt

Link to comment
Share on other sites

From the manual:

Quote

Operands of modulo are converted to int before processing.

So when you're dividing your timestamp variable, you get a floating point number due to the values not dividing evenly.  Attempting to use % on that result causes PHP to convert it to an integer instead, loosing whatever fractional value existed in the process.  In the past, this happened silently.  Now there's the notice about it to highlight the potential bug.  Convert your floating point value to an integer value yourself explicitly to remove the error.  You can do this in that code by just changing the floor function to only operate on the division instead of the whole expression.

$hours       += floor($timestamp / 3600) % 24;
$min         = floor($timestamp / 60) % 60;

 

  • Great Answer 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.