|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80170 incorrect floating
Submitted: 2020-10-01 18:12 UTC Modified: 2020-10-02 08:32 UTC
From: wapinet at mail dot ru Assigned:
Status: Not a bug Package: Math related
PHP Version: 8.0.0beta4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: wapinet at mail dot ru
New email:
PHP Version: OS:


 [2020-10-01 18:12 UTC] wapinet at mail dot ru

Test script:
var_dump(34.99 - 10);

// Output for 8.0.0alpha1 - beta4
//     float(24.990000000000002)
// Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.23, 7.4.0 - 7.4.11
//     float(24.99)

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-01 18:41 UTC]
-Status: Open +Status: Not a bug
 [2020-10-01 18:41 UTC]
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:

Thank you for your interest in PHP.

 [2020-10-01 21:03 UTC] wapinet at mail dot ru
i think it mentions to this note
and in real life we actually have usually string "24.99" -
 [2020-10-02 08:32 UTC]
@wapinet at mail dot ru: Could you please clarify what the bug here is supposed to be? You are right that 24.99 is the more useful representation for end-users ... and they will still get it, because that's the formatting you'll see if you cast the number to string, print it with "echo" etc. This change only affects the output of var_dump(), which is a debugging function, where it is important to see the exact result.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 21:01:30 2024 UTC