|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2014-08-14 05:40 UTC] keyur_govande at yahoo dot com
[2014-08-15 23:52 UTC] keyur@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: keyur
[2014-08-15 23:52 UTC] keyur@php.net
[2014-10-19 08:09 UTC] nikita at paymentwall dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Description: ------------ mysqli does not handle 4-byte floats correctly. It casts it into a double which essentially increases the "error" in the IEEE-754 FP number. Consider the following C code: float a = 99.99f; double b = (double) a; The output will be: a = 99.9899979 b = 99.989997863769531 b will never be printed as 99.99 Test script: --------------- On a MySQL DB, run the following queries: CREATE TABLE test(id INT PRIMARY KEY, fp4 FLOAT, fp8 DOUBLE) ENGINE = InnoDB; INSERT INTO test(id, fp4, fp8) VALUES (1, 9.9999, 9.9999) Now using mysqli, SELECT the one row out: if (!($stmt = mysqli_prepare($link, "SELECT id, fp4, fp8 FROM test"))) { die(); } if (!mysqli_stmt_execute($stmt)) { die(); } if (!($result = mysqli_stmt_get_result($stmt))) { die(); } $data = mysqli_fetch_assoc($result); print $data['id'] . ": " . $data['fp4'] . ": " . $data['fp8'] . "\n"; Expected result: ---------------- It should be: 1: 9.9999: 9.9999 Actual result: -------------- The output will be: 1: 9.9998998641968: 9.9999