php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43618 missing leading zero in float value
Submitted: 2007-12-17 15:09 UTC Modified: 2007-12-17 23:28 UTC
Votes:8
Avg. Score:3.9 ± 0.8
Reproduced:7 of 7 (100.0%)
Same Version:2 (28.6%)
Same OS:1 (14.3%)
From: marcin dot krzyzanowski at gmail dot com Assigned:
Status: Wont fix Package: OCI8 related
PHP Version: 5.2.5 OS: Windows XP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-12-17 15:09 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-17 18:59 UTC] sixd@php.net
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]);

?>

 [2007-12-17 23:28 UTC] marcin dot krzyzanowski at gmail dot com
well but cast require to have set NLS_NUMERIC_CHARACTERS = '. ' but for my locales: ', ' is adequate and cast to float return "0.0000" instead of any value.

NLS_LANGUAGE=Polish

Is it possible to sync PHP with Oracle Locales automatically and get work all that stuff ?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Oct 05 18:05:54 2022 UTC