#43618 [Opn->WFx]: missing leading zero in float value
| From: | sixd@php.net | Date: | Mon, 17 Dec 2007 18:59:01 +0000 |
| Subject: | #43618 [Opn->WFx]: missing leading zero in float value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120714@lists.php.net to get a copy of this message | ||
ID: 43618
Updated by: sixd@php.net
Reported By: marcin dot krzyzanowski at gmail dot com
-Status: Open
+Status: Wont fix
Bug Type: OCI8 related
Operating System: Windows XP
PHP Version: 5.2.5
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
+--------------------------------------------------------------
|
| This is a consequence of PHP's general preference for strings and
the
| default formatting used. With Oracle, formatting depends on the
data
| access tool. For example by default, SQL*Plus also doesn't give
| leading zeros but a COLUMN, SET NUMBER, or SET NUMWIDTH command will
| affect display. PHP lets you cast, format numbers with sprintf,
| or use TO_CHAR in queries.
|
| SQL> select col1 from bug43618_tab;
|
| COL1
| ----------
| .1666
|
| SQL> set numformat 0999.9999
| SQL> select col1 from bug43618_tab;
|
| COL1
| ----------
| 0000.1666
|
+--------------------------------------------------------------
<?php
/*
Output is:
Basic query: string(5) ".1666"
Cast as float: float(0.1666)
printf as float: 0.166600
TO_CHAR: string(10) " 0000.1666"
*/
$c = oci_connect("hr", "hrpwd", "ca-tools1/orcl");
$stmtarray = array("drop table bug43618_tab",
"create table bug43618_tab(col1 number)",
"insert into bug43618_tab values (0.1666)"
);
foreach ($stmtarray as $stmt) {
$s = oci_parse($c, $stmt);
@oci_execute($s);
}
$statement = oci_parse ($c, "select col1 from bug43618_tab");
oci_execute ($statement);
$row = oci_fetch_array ($statement, OCI_NUM);
echo "Basic query: ";
var_dump($row[0]);
echo "Cast as float: ";
var_dump((float)$row[0]);
printf("printf as float: %f\n", $row[0]);
$statement = oci_parse ($c,
"select to_char(col1, '0999.9999') from
bug43618_tab");
oci_execute ($statement);
$row = oci_fetch_array ($statement, OCI_NUM);
echo "TO_CHAR: ";
var_dump($row[0]);
?>
Previous Comments:
------------------------------------------------------------------------
[2007-12-17 15:09:15] marcin dot krzyzanowski at gmail dot com
Description:
------------
There is missing leading zero for float values
Reproduce code:
---------------
$connection = oci_connect("fit","wyoming","blue1.fitdm.pl");
$statement = oci_parse ($connection, "SELECT NUMBER_COLUMN FROM
TABLE");
oci_execute ($statement);
while ($row = oci_fetch_array ($statement, OCI_BOTH)) {
echo $row[0]."</br>";
}
Expected result:
----------------
0,1666
Actual result:
--------------
,1666
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43618&edit=1