#39126 [NEW]: String->float->String conversion behavior

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #39126 [NEW]: String->float->String conversion behavior

    From: bobson at rpg dot pl
    Operating system: Linux
    PHP version: 5CVS-2006-10-11 (snap)
    PHP Bug Type: Unknown/Other Function
    Bug description: String->float->String conversion behavior

    Description:
    ------------
    When converting to float from string, its always use "." as a decimal
    separator, but echo shows decimal separator using locale definition.
    Because of that there's a problem eg. in dbase function on numeric(float)
    fields.

    Reproduce code:
    ---------------
    setlocale(LC_ALL,"pl_PL");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1,2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- this was expected to produce 1,2 float on pl_PL (in
    PL decimal separator is ",")

    setlocale(LC_ALL,"en_EN");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1.2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- correct on en_EN

    //the most ugly examlpe
    setlocale(LC_ALL,"pl_PL");
    echo (("1.2"*1)."")*1; //produce 1
    echo (("1,2"*1)."")*1; //also produce 1


    Expected result:
    ----------------
    on pl_PL
    1
    1,2

    on en_EN
    1.2
    1

    last one example code:
    1
    1,2

    Actual result:
    --------------
    on pl_PL
    1,2
    1

    on en_EN
    1.2
    1

    last one example code:
    1
    1

    --
    Edit bug report at [url]http://bugs.php.net/?id=39126&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39126&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39126&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39126&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39126&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39126&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39126&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39126&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39126&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39126&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39126&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39126&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39126&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39126&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39126&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39126&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39126&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39126&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39126&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39126&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39126&r=mysqlcfg[/url]
    bobson at rpg dot pl Guest

  2. Similar Questions and Discussions

    1. help float to string
      try the sprintf print sprint("%.02f", $f); if I'm not rong; -----Original Message----- From: perl@swanmail.com
    2. #25562 [Opn->Bgs]: Float to String to Float conversion error
      ID: 25562 Updated by: helly@php.net Reported By: daseymour at 3hc dot org -Status: Open +Status: ...
    3. #25562 [NEW]: Float to String to Float conversion error
      From: daseymour at 3hc dot org Operating system: and PHP version: 4.3.3 PHP Bug Type: Math related Bug description: Float...
    4. How to convert string to float?
      i want to covert a querystring to float number in asp. what function should i use? i know cint() can convert string to int but how about float?
    5. preventing string conversion to float.
      It has been a long time since I touched any perl, and I am having a problem with parsing a text file. I need to pull out a string in the form...
  3. #2

    Default #39126 [Opn->Bgs]: String->float->String conversion behavior

    ID: 39126
    Updated by: [email]tony2001@php.net[/email]
    Reported By: bobson at rpg dot pl
    -Status: Open
    +Status: Bogus
    Bug Type: Unknown/Other Function
    Operating System: Linux
    PHP Version: 5CVS-2006-10-11 (snap)
    New Comment:

    The output may differe depending on your localem but the input must
    always be the same, otherwise your script would not work on servers
    with different locales.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-10-11 15:32:13] bobson at rpg dot pl

    Description:
    ------------
    When converting to float from string, its always use "." as a decimal
    separator, but echo shows decimal separator using locale definition.
    Because of that there's a problem eg. in dbase function on
    numeric(float) fields.

    Reproduce code:
    ---------------
    setlocale(LC_ALL,"pl_PL");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1,2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- this was expected to produce 1,2 float on pl_PL
    (in PL decimal separator is ",")

    setlocale(LC_ALL,"en_EN");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1.2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- correct on en_EN

    //the most ugly examlpe
    setlocale(LC_ALL,"pl_PL");
    echo (("1.2"*1)."")*1; //produce 1
    echo (("1,2"*1)."")*1; //also produce 1


    Expected result:
    ----------------
    on pl_PL
    1
    1,2

    on en_EN
    1.2
    1

    last one example code:
    1
    1,2

    Actual result:
    --------------
    on pl_PL
    1,2
    1

    on en_EN
    1.2
    1

    last one example code:
    1
    1


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39126&edit=1[/url]
    tony2001@php.net Guest

  4. #3

    Default #39126 [Bgs]: String->float->String conversion behavior

    ID: 39126
    User updated by: bobson at rpg dot pl
    Reported By: bobson at rpg dot pl
    Status: Bogus
    Bug Type: Unknown/Other Function
    Operating System: Linux
    PHP Version: 5CVS-2006-10-11 (snap)
    New Comment:

    Yes and no in fact.
    Using the same decimal separator on all platform is nice but-
    When you using input from browser (POST) in Poland you will get "," as
    decimal separator when someone type from numeric keypad.
    Second:
    Try to read dbase file with numeric(4,2) field and float value in it.
    Set locale to "pl_PL" first. Because of float->string translation using
    locale you will never get float from that numeric (because dbase reading
    procedure make float->string->float convert. float->string using locale.
    string->float without using locale. It makes value truncated to integer
    part of it).


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-10-11 15:59:45] [email]tony2001@php.net[/email]

    The output may differe depending on your localem but the input must
    always be the same, otherwise your script would not work on servers
    with different locales.

    ------------------------------------------------------------------------

    [2006-10-11 15:32:13] bobson at rpg dot pl

    Description:
    ------------
    When converting to float from string, its always use "." as a decimal
    separator, but echo shows decimal separator using locale definition.
    Because of that there's a problem eg. in dbase function on
    numeric(float) fields.

    Reproduce code:
    ---------------
    setlocale(LC_ALL,"pl_PL");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1,2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- this was expected to produce 1,2 float on pl_PL
    (in PL decimal separator is ",")

    setlocale(LC_ALL,"en_EN");
    echo '1.2*1=';
    echo "1.2"*1;
    //produce 1.2*1=1.2
    echo '1,2*1=';
    echo "1,2"*1;
    //produce 1,2*1=1 <- correct on en_EN

    //the most ugly examlpe
    setlocale(LC_ALL,"pl_PL");
    echo (("1.2"*1)."")*1; //produce 1
    echo (("1,2"*1)."")*1; //also produce 1


    Expected result:
    ----------------
    on pl_PL
    1
    1,2

    on en_EN
    1.2
    1

    last one example code:
    1
    1,2

    Actual result:
    --------------
    on pl_PL
    1,2
    1

    on en_EN
    1.2
    1

    last one example code:
    1
    1


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39126&edit=1[/url]
    bobson at rpg dot pl Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139