|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-01-20 21:14 UTC] heiglandreas@php.net
-Status: Open
+Status: Feedback
-Package: PDO_ODBC
+Package: *General Issues
[2017-01-20 21:14 UTC] heiglandreas@php.net
[2017-01-29 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 07:00:01 2025 UTC |
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.