php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25279 real numbers get twisted
Submitted: 2003-08-27 14:04 UTC Modified: 2003-08-28 08:33 UTC
From: t dot noest at noestnet dot nl Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.3 OS: winnt
Private report: No CVE-ID: None
 [2003-08-27 14:04 UTC] t dot noest at noestnet dot nl
Description:
------------
I just installed PHP4.3.3, the binary windows build, on my winnt machine. 

Something is going wrong with the real numbers I put in the MSSQL 7 database(fieldtype = "real").

I save for instance the number 7.02: "UPDATE Teksten SET Volgorde_nummer = 7.02 WHERE RecID = 220"
MSSQLServer say's the value in the database is 7.02.
When pulled back by PHP: "SELECT * FROM Teksten WHERE RecID = 220" 
$rs = mssql_query($SQL);
$k = mssql_fetch_array($rs);
echo $k['Volgorde_nummer'];
give's me : 7.01999998093

And worse:
"UPDATE Teksten SET Volgorde_nummer = 7.01 WHERE RecID = 220"
Now MSSQLServer say's the value in the database is 7.0100002.
echo $k['Volgorde_nummer'];
give's me : 7.01000022888

I got the newest mssql.dll from the zip distribution. But it doesn't make any difference.

I have had these problems with almost every new version of PHP I install!



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-27 15:02 UTC] abies@php.net
This is a known limitation of floating point numbers. This has nothing to do with either the database or PHP. If you want perfect accuracy, use a 'money' or 'numeric' field. 
 [2003-08-28 08:33 UTC] t dot noest at noestnet dot nl
Oepsh! You are right. I forgot. Sorry, and thanks

Thomas
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC