Bug #57151 [Fbk->NoF]: Decimal Data Type Precision Problem

From: Date: Sun, 29 Jan 2017 04:22:55 +0000
Subject: Bug #57151 [Fbk->NoF]: Decimal Data Type Precision Problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207028@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: php-bugs@lists.php.net Reported by: kfbombar at us dot ibm dot com Summary: Decimal Data Type Precision Problem -Status: Feedback +Status: No Feedback Type: Bug Package: *General Issues Operating System: Linux PHP Version: 5.1.4 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2017-01-20 21:14:52] heiglandreas@php.net Is this still relevant? ------------------------------------------------------------------------ [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

« previous php.bugs (#207028) next »