php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72487 100 - 99.6 why result = 0.400000001
Submitted: 2016-06-24 11:37 UTC Modified: 2016-06-24 19:18 UTC
From: wee_weerapat at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.37 OS: Mac & Windows
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: wee_weerapat at hotmail dot com
New email:
PHP Version: OS:

 

 [2016-06-24 11:37 UTC] wee_weerapat at hotmail dot com
Description:
------------
I'm not sure. 100-99.6 the result will return 0.400000001
and i try many case 100 - 99.96 the result still same 0.040000000000006
There return another position of number

Test script:
---------------
echo 100-99.6;
echo "<br>";
echo 100-99.96;
echo "<br>";
echo 1000-999.96;

Expected result:
----------------
0.4
0.04
0.04

Actual result:
--------------
0.40000000000001
0.040000000000006
0.039999999999964

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-24 11:40 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2016-06-24 11:40 UTC] rasmus@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://www.floating-point-gui.de/

Thank you for your interest in PHP.

.
 [2016-06-24 11:46 UTC] wee_weerapat at hotmail dot com
Oh I see. Thank you so much.
 [2016-06-24 19:18 UTC] stas@php.net
-Package: PHP Language Specification +Package: *General Issues
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC