Bug #63684 [Opn->Nab]: pdo sqlite round function can't work correct
Edit report at https://bugs.php.net/bug.php?id=63684&edit=1
ID: 63684
Updated by: aharvey@php.net
Reported by: roastduck at qq dot com
Summary: pdo sqlite round function can't work correct
-Status: Open
+Status: Not a bug
Type: Bug
Package: PDO related
Operating System: windows xp
PHP Version: 5.3.19
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2012-12-04 08:40:02] roastduck at qq dot com
Description:
------------
when I used pdo for the sql "select round(863521.777777778, 2) as a", it gets
wrong result 863521.780000001
Test script:
---------------
<?php
$db = new PDO("sqlite:../test.s3db");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$st = $db->query('select round(863521.777777778, 2) as a');
$data = $st->fetchAll();
print_r($data);
$st = $db->query('select round(372366.577777778, 2) as a');
$data = $st->fetchAll();
print_r($data);
Expected result:
----------------
Array
(
[0] => Array
(
[a] => 863521.780000001
[0] => 863521.780000001
)
)
Array
(
[0] => Array
(
[a] => 372366.58
[0] => 372366.58
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63684&edit=1
Thread (2 messages)