From:
Operating system: Linux
PHP version: 5.3.6
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli: truncated floats
Description:
------------
There's an inconsistency in behaviour between mysqli and PDO_MSYQL in the
following SELECT, e.g.,
SELECT TRUNCATE(SUM(aFloatColumn),2) FROM aTable;
Let's say the sum of the column is 42.001.
With PDO_MYSQL, you'll get "42.00".
But with MYSQLI, you'll instead get "42".
Test script:
---------------
<?php
$link = mysqli_connect("localhost", "user", "password", "dbname");
$query = 'CREATE TABLE t (f FLOAT)';
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
$query = 'TRUNCATE TABLE t';
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
$query = 'INSERT INTO t (f) VALUES (42.001)';
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
$query = "SELECT truncate(sum(f), 2) from t";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $revenue);
while (mysqli_stmt_fetch($stmt)) {
printf ("%s\n", $revenue);
}
mysqli_stmt_close($stmt);
mysqli_close($link);
Expected result:
----------------
42.00
Actual result:
--------------
42
--
Edit bug report at http://bugs.php.net/bug.php?id=54508&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54508&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54508&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54508&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54508&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54508&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54508&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54508&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54508&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54508&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54508&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54508&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54508&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54508&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54508&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54508&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54508&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54508&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54508&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54508&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54508&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54508&r=mysqlcfg