php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6851 "floor()" function rounds down an integer that resulted from a division
Submitted: 2000-09-22 04:22 UTC Modified: 2000-09-24 17:05 UTC
From: virtual dot spirit at digi dot com dot br Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.2 OS: RedHat Linux 6.1
Private report: No CVE-ID: None
 [2000-09-22 04:22 UTC] virtual dot spirit at digi dot com dot br
# Script reproducing the problem:
$raw_result = (14056567/(14056567/100));
# the line below will generate error, too
# $raw_result = (140565637/(140565637/100));

$round = floor($raw_result);
echo "Raw result: $raw_result\nRounded: $round\n";


# Tested with two different PHP builds:
# ./configure --with-apxs --with-mysql --enable-ftp
# and
# ./configure --with-mysql --enable-ftp

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-22 04:38 UTC] virtual dot spirit at digi dot com dot br
When using floor to round a result of a division of some specific numbers,
it rounds down a integer number.
In a division like the one below, it rounds 100 to 99. But, if you change
14056567 to another number, it will probably work fine, except when using
some numbers like 140565637.

# Script reproducing the problem:
$raw_result = (14056567/(14056567/100));
# the line below will generate error, too
# $raw_result = (140565637/(140565637/100));

$round = floor($raw_result);
echo "Raw result: $raw_result\nRounded: $round\n";

# Tested with two different PHP builds:
# --with-apxs --with-mysql --enable-ftp
# and --with-mysql --enable-ftp
 [2000-09-24 17:05 UTC] stas@php.net
This is expected result. 100 is the same as 99.9999999999(9) in floats. Try it in any other language, like Perl or C, you get the same.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC