php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81410 floatval() adds extra precision to certain numbers
Submitted: 2021-09-03 08:34 UTC Modified: 2021-09-03 08:43 UTC
From: mrpramodjodhani at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0Git-2021-09-03 (Git) OS: MacOC Catalina
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mrpramodjodhani at gmail dot com
New email:
PHP Version: OS:

 

 [2021-09-03 08:34 UTC] mrpramodjodhani at gmail dot com
Description:
------------
$num = floatval( 45.34 );
var_dump( $num );

The output of the above script is `float(45.340000000000003)`

The same problem happens when I use (float) type convertor. 

$num = (float) 45.34;
var_dump( $num );


Test script:
---------------
$num = floatval( 45.34 );
var_dump( $num );

Expected result:
----------------
float(45.34)

Actual result:
--------------
float(45.340000000000003)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-03 08:37 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-09-03 08:37 UTC] nikic@php.net
Please make sure you have the serialize_precision ini setting set to the default value of -1. You should never use a different value for serialize_precision.
 [2021-09-03 08:43 UTC] mrpramodjodhani at gmail dot com
-Summary: floatval() add extra precision to certain numbers +Summary: floatval() adds extra precision to certain numbers
 [2021-09-03 08:43 UTC] mrpramodjodhani at gmail dot com
updated title
 [2021-09-03 09:00 UTC] mrpramodjodhani at gmail dot com
Hello nikic@php.net,

Thank you! It solved the problem.

I think the problem is with LocalWP which I'm using. I will send them a mail regarding this. 

Thanks again for your help.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC