php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75004 Certain floats * 100 type cast to int value one less then they should be
Submitted: 2017-07-28 16:12 UTC Modified: 2017-07-28 16:13 UTC
From: c dot m dot tatro at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.1.7 OS: ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: c dot m dot tatro at gmail dot com
New email:
PHP Version: OS:

 

 [2017-07-28 16:12 UTC] c dot m dot tatro at gmail dot com
Description:
------------
PHP 7.1.7-1+ubuntu14.04.1+deb.sury.org+1 (cli) (built: Jul  7 2017 10:07:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.7-1+ubuntu14.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

echo (int) (66.74*100); // 6673
echo (int) (35.55*100); // 3554
echo (int) (34.12*100); // 3411

To get a larger list run:
for ($i=0; $i<=1000; $i++) { echo (int) (((float)$i/100)*100) ."\r\n";}


Test script:
---------------
echo (int) (66.74*100);
echo (int) (35.55*100);
echo (int) (34.12*100);
for ($i=0; $i<=1000; $i++) { echo (int) (((float)$i/100)*100) ."\r\n";}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-28 16:13 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-07-28 16:13 UTC] requinix@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 15:01:33 2025 UTC