php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53549 Rounding twice yields a different result than rounding once
Submitted: 2010-12-15 11:03 UTC Modified: 2010-12-15 14:27 UTC
From: jeffreybolle at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.4 OS: ALL
Private report: No CVE-ID: None
 [2010-12-15 11:03 UTC] jeffreybolle at gmail dot com
Description:
------------
Rounding a float once should result in the same value as rounding it more than once.

Test script:
---------------
<?php
$float = -1.1368683772162E-13;
var_dump(round($float, 2));
var_dump(round(round($float, 2), 2));


Expected result:
----------------
float(0)
float(0)

Actual result:
--------------
float(-0)
float(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-15 14:27 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-12-15 14:27 UTC] johannes@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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC