php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52872 Basic math operation returns incorrect result
Submitted: 2010-09-17 16:43 UTC Modified: 2010-09-17 17:13 UTC
From: ndesbarats at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: Windows 7
Private report: No CVE-ID: None
 [2010-09-17 16:43 UTC] ndesbarats at gmail dot com
Description:
------------
See test script below.

Test script:
---------------
<?php

$num = 123456.123456;

echo 'remainder: '.($num - (integer)$num).'<br />';

// remainder should be 0.123456
// instead, I get a remainder of 0.12345600000117 (!!!!!!!)

?>

Expected result:
----------------
// remainder should be 0.123456


Actual result:
--------------
// instead, I get a remainder of 0.12345600000117 (!!!!!!!)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-17 17:13 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-09-17 17:13 UTC] rasmus@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://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

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