Bug #67978 [Opn->Nab]: Bug with floating number
| From: | requinix@php.net | Date: | Mon, 08 Sep 2014 15:08:09 +0000 |
| Subject: | Bug #67978 [Opn->Nab]: Bug with floating number | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187452@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67978&edit=1
ID: 67978
Updated by: requinix@php.net
Reported by: tripollite at gmail dot com
Summary: Bug with floating number
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: Debian 7
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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://www.floating-point-gui.de/
Thank you for your interest in PHP.
If you need numbers rounded to a certain precision then you need to do that yourself.
Previous Comments:
------------------------------------------------------------------------
[2014-09-08 12:47:16] tripollite at gmail dot com
Description:
------------
Var dump fail to show right number but this number is used in memory to make calcul.
it should respect precision by cutting floating numbers
or showing the right number
Test script:
---------------
http://3v4l.org/AFQF6
<?php
$b = 0.27*28;
$a = round($b,2);
var_dump($a-$b);
$b = 0.270000000000001;
$a = round($b,2);
var_dump($b);var_dump($a-$b);
Expected result:
----------------
float(0)
float(0.27)
float(0)
Actual result:
--------------
float(-8.8817841970013E-16)
float(0.27)
float(-9.9920072216264E-16)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67978&edit=1