Bug #57151 [Opn->Fbk]: Decimal Data Type Precision Problem
| From: | heiglandreas@php.net | Date: | Fri, 20 Jan 2017 21:14:53 +0000 |
| Subject: | Bug #57151 [Opn->Fbk]: Decimal Data Type Precision Problem | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206800@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=57151&edit=1
ID: 57151
Updated by: heiglandreas@php.net
Reported by: kfbombar at us dot ibm dot com
Summary: Decimal Data Type Precision Problem
-Status: Open
+Status: Feedback
Type: Bug
-Package: PDO_ODBC
+Package: *General Issues
Operating System: Linux
PHP Version: 5.1.4
Block user comment: N
Private report: N
New Comment:
Is this still relevant?
Previous Comments:
------------------------------------------------------------------------
[2006-07-24 14:09:25] kfbombar at us dot ibm dot com
Description:
------------
My understanding is that to store a value range of -179.999999 to +179.999999 as a decimal with 6
decimal places in a DB2 table, DECIMAL(9,6) is appropriate and this works when I use the Command
Center to add and view data.
It seems that the number of returned decimal places is determined by
(DB2 DECIMAL LENGTH) - ((1 if negative, else 0) + (number of integer digits) + (1 for decimal
point))
e.g.
-179.999999 becomes -179.9999pp 9-(1+3+1) = 4
179.999999 becomes 179.99999p 9-(0+3+1) = 5
99.999999 becomes 99.999999 9-(0+2+1) = 6
Reproduce code:
---------------
<?php
$dbh = new PDO('odbc:SAMPLE', 'db2user', 'db2pass');
if ($dbh) {
$dbh->exec("DROP TABLE TEST");
$dbh->exec("CREATE TABLE TEST (id INTEGER, problem9 DECIMAL(9,6), problem10 DECIMAL(10,6),
problem11 DECIMAL(11,6))");
$dbh->exec("INSERT INTO TEST (id, problem9, problem10, problem11) values (1, 1.999999,
2.999999, 3.999999)");
$dbh->exec("INSERT INTO TEST (id, problem9, problem10, problem11) values (1, -1.999999,
-2.999999, -3.999999)");
$dbh->exec("INSERT INTO TEST (id, problem9, problem10, problem11) values (1, -179.999999,
-279.999999, -379.999999)");
$stmt = $dbh->prepare("SELECT * FROM TEST");
if ($stmt->execute()) {
while (($row = $stmt->fetch()) !== false) {
$prob1 = $row[1];
$prob2 = $row[2];
$prob3 = $row[3];
echo $prob1 . " AAA is a " . gettype($prob1) . ".\n";
echo $prob2 . " BBB is a " . gettype($prob2) . ".\n";
echo $prob3 . " CCC is a " . gettype($prob3) . ".\n";
}
}
} else {
echo "Not connected";
}
?>
Expected result:
----------------
1.999999 AAA is a string.
2.999999 BBB is a string.
3.999999 CCC is a string.
-1.999999 AAA is a string.
-2.999999 BBB is a string.
-3.999999 CCC is a string.
-179.999999 AAA is a string.
-279.999999 BBB is a string.
-379.999999 CCC is a string.
Actual result:
--------------
1.999999 AAA is a string.
2.999999 BBB is a string.
3.999999 CCC is a string.
-1.999999 AAA is a string.
-2.999999 BBB is a string.
-3.999999 CCC is a string.
-179.9999
AAA is a string.
-279.99999 BBB is a string.
-379.999999 CCC is a string.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=57151&edit=1