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
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: 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

Pull Requests

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: Sat Dec 21 17:01:58 2024 UTC