Bug #75240 [Com]: Remainder of $a divided by 1 is always 0
| From: | sjon at hortensius dot net | Date: | Thu, 21 Sep 2017 07:39:53 +0000 |
| Subject: | Bug #75240 [Com]: Remainder of $a divided by 1 is always 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211290@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75240&edit=1
ID: 75240
Comment by: sjon at hortensius dot net
Reported by: miami at blackcrystal dot net
Summary: Remainder of $a divided by 1 is always 0
Status: Not a bug
Type: Bug
Package: Math related
Operating System: Ubuntu 16.04.3
PHP Version: 7.0.23
Block user comment: N
Private report: N
New Comment:
The explanation is also in the documentation:
"Operands of modulo are converted to integers (by stripping the decimal part) before
processing. For floating-point modulo, see fmod()."
Previous Comments:
------------------------------------------------------------------------
[2017-09-21 07:38:47] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
> Operands of modulo are converted to integers (by stripping the decimal part)
> before processing. For floating-point modulo, see fmod().
------------------------------------------------------------------------
[2017-09-21 07:32:25] miami at blackcrystal dot net
Description:
------------
---
From manual page: http://www.php.net/language.operators.arithmetic
---
PHP7 always returns 0 as remainder after division to 1.
<?php
echo (1 % 1; // 0, ok
echo 1.5 % 1; // 0, must be .5
echo 2.234567 % 1; // 0, must be .234567
?>
Test script:
---------------
<?php
echo (1 % 1) ."\n";
echo (1.5 % 1) ."\n";
echo (2.234567 % 1) ."\n";
?>
Expected result:
----------------
0
.5
.234567
Actual result:
--------------
0
0
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75240&edit=1