php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74109 round() PHP_ROUND_HALF_DOWN mode is broken
Submitted: 2017-02-16 13:52 UTC Modified: 2017-02-16 15:42 UTC
From: pandenitz at mail dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.16 OS: Win 7 64
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: pandenitz at mail dot ru
New email:
PHP Version: OS:

 

 [2017-02-16 13:52 UTC] pandenitz at mail dot ru
Description:
------------
PHP_ROUND_HALF_DOWN mode for round() doesn't work, it still increments last allowed decimal digit if next is larger than 4

Test script:
---------------
var_dump(100 / 6);
var_dump(round(100 / 6, 4, PHP_ROUND_HALF_UP));
var_dump(round(100 / 6, 4, PHP_ROUND_HALF_DOWN));

Expected result:
----------------
float 16.666666666667
float 16.6667
float 16.6666

Actual result:
--------------
float 16.666666666667
float 16.6667
float 16.6667

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-16 15:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-02-16 15:42 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

http://php.net/manual/en/function.round.php
> Round val down to precision decimal places towards zero, when it is half way
> there. Making 1.5 into 1 and -1.5 into -1.

6 is not half way.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 07:01:32 2025 UTC