php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75240 Remainder of $a divided by 1 is always 0
Submitted: 2017-09-21 07:32 UTC Modified: 2017-09-21 07:38 UTC
From: miami at blackcrystal dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 7.0.23 OS: Ubuntu 16.04.3
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
50 + 28 = ?
Subscribe to this entry?

 
 [2017-09-21 07:32 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-21 07:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-09-21 07:38 UTC] 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:39 UTC] sjon at hortensius dot net
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()."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 06:01:28 2024 UTC