php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11953 wrong conversion from data type NUMERIC with decimal places into string
Submitted: 2001-07-07 22:23 UTC Modified: 2002-05-25 09:22 UTC
From: phpbug at mts dot cz Assigned:
Status: Closed Package: InterBase related
PHP Version: 4.0.5 OS: Linux
Private report: No CVE-ID: None
 [2001-07-07 22:23 UTC] phpbug at mts dot cz
When the database column has type NUMERIC(10,3) and you stored value 12.01, when you would like to retrieve it you get 10.1. Following patch fixes this bug.

Regards, Libor Chocholaty

--- php-4.0.5-orig/ext/interbase/interbase.c    Mon Feb 26 07:07:00 2001
+++ php-4.0.5/ext/interbase/interbase.c Sun Jul  8 04:02:11 2001
@@ -25,6 +25,10 @@
 
 /*
        Changes:
+               2001-07-08:     Libor Chocholaty <chocholaty@obolus.cz>
+                       - fixed problem with conversion from numeric
+                         with decimal places internally stored as
+                         ISC_INT64 to string.
                1999-09-21:     Ivo Panacek <ivop@regionet.cz>
                        - added COMPILE_DL section
                        - more verbose php_info_ibase function
@@ -1778,11 +1782,24 @@
                        break;
 #ifdef SQL_INT64
                case SQL_INT64:
-                       val->type = IS_STRING;
-                       val->value.str.len = sprintf(string_data, "%Ld.%Ld",
-                                                                                (ISC_INT64) (*((ISC_INT64 *)data) / (int) pow(-                                                                                (ISC_INT64) abs((int) (*((ISC_INT64 *)data) %
-                       val->value.str.val = estrdup(string_data);
+                       {
+                               char aux_str[40], *fract;
+                               long long aux_long = (ISC_INT64) abs((int) (*((ISC_INT64 *)data) % (int) pow(10.0, (double) -sc+                               sprintf(aux_str, "0000000000000000000%Ld", aux_long);
+                               fract = aux_str + strlen(aux_str) + scale;
+
+
+                               val->type = IS_STRING;
+
+                               sprintf(string_data, "%Ld", (ISC_INT64) (*((ISC_INT64 *)data) / (int) pow(10.0, (double) -scale+                               if (aux_long)
+                               {
+                                       strcat(string_data, ".");
+                                       strcat(string_data, fract);
+                               }
+                               val->value.str.len = strlen(string_data);
+                               val->value.str.val = estrdup(string_data);
+                       }
                        break;
 #endif
 #ifndef SQL_TIMESTAMP                                                                                                         

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-25 09:22 UTC] derick@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 15 16:05:46 2022 UTC