php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57151 Decimal Data Type Precision Problem
Submitted: 2006-07-24 14:09 UTC Modified: 2017-01-29 04:22 UTC
From: kfbombar at us dot ibm dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-07-24 14:09 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
Is this still relevant?
 [2017-01-29 04:22 UTC] php-bugs at lists dot php dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 22:01:29 2024 UTC