Professional Web Applications Themes
  1. #1

    Default #40622 [NEW]: round function

    From: bruno dot boccara at d2b dot com
    Operating system: windows 2003 Apache 2
    PHP version: 4.4.5
    PHP Bug Type: Math related
    Bug description: round function

    Description:
    ------------
    round function gives wrong value.

    Please do not send me to
    [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url], you have to admit
    that this is a bug !!!!!
    if not, php CANNOT be use in production site with mathematical functions
    !!!

    Reproduce code:
    ---------------
    <?
    // 140.25*(1-(34/100)) = 92.565


    echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>";

    echo "direct = ".round (92.565, 2);echo "<br>";

    $valeur = 140.25*(1-(34/100));

    echo "value = ".round($valeur,2);echo "<br>";

    settype($valeur,"string");
    settype($valeur,"float");

    echo "value2 = ".round($valeur,2);

    ?>

    Expected result:
    ----------------
    formula = 92.57
    direct = 92.57
    value = 92.57
    value2 = 92.57

    Actual result:
    --------------
    formula = 92.56 // WRONG !
    direct = 92.57
    value = 92.56 // WRONG !
    value2 = 92.57

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

  2. #2

    Default #40622 [Opn->Bgs]: round function

    ID: 40622
    Updated by: [email]johannes@php.net[/email]
    Reported By: bruno dot boccara at d2b dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Math related
    Operating System: windows 2003 Apache 2
    PHP Version: 4.4.5
    New Comment:

    Floating point values have a limited precision. Hence a value might
    not have the same string representation after any processing. That also
    includes writing a floating point value in your script and directly
    printing it without any mathematical operations.

    If you would like to know more about "floats" and what IEEE
    754 is read this:
    [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url]

    Thank you for your interest in PHP.

    ..


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

    [2007-02-24 21:36:47] bruno dot boccara at d2b dot com

    Description:
    ------------
    round function gives wrong value.

    Please do not send me to
    [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url], you have to
    admit that this is a bug !!!!!
    if not, php CANNOT be use in production site with mathematical
    functions !!!

    Reproduce code:
    ---------------
    <?
    // 140.25*(1-(34/100)) = 92.565


    echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>";

    echo "direct = ".round (92.565, 2);echo "<br>";

    $valeur = 140.25*(1-(34/100));

    echo "value = ".round($valeur,2);echo "<br>";

    settype($valeur,"string");
    settype($valeur,"float");

    echo "value2 = ".round($valeur,2);

    ?>

    Expected result:
    ----------------
    formula = 92.57
    direct = 92.57
    value = 92.57
    value2 = 92.57

    Actual result:
    --------------
    formula = 92.56 // WRONG !
    direct = 92.57
    value = 92.56 // WRONG !
    value2 = 92.57


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


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

  3. #3

    Default #40622 [Bgs]: round function

    ID: 40622
    User updated by: bruno dot boccara at d2b dot com
    Reported By: bruno dot boccara at d2b dot com
    Status: Bogus
    Bug Type: Math related
    Operating System: windows 2003 Apache 2
    PHP Version: 4.4.5
    New Comment:

    Did I send an email to a robot ??
    Each user who ask this question get the same answer.
    You should be ashaimed to do this. You know that this is a a very big
    bug of PHP and no one is ready to resolve it !

    This is not a way to do.
    I'm very very desappointed.

    For other users with this problem, you can do like me in the example to
    avoid this problem. This will slow down a little the result. Use the
    settype function to convert the number to string and then to float. I
    did'n test it in all cases, but it seems to work.


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

    [2007-02-24 22:05:52] [email]johannes@php.net[/email]

    Floating point values have a limited precision. Hence a value might
    not have the same string representation after any processing. That also
    includes writing a floating point value in your script and directly
    printing it without any mathematical operations.

    If you would like to know more about "floats" and what IEEE
    754 is read this:
    [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url]

    Thank you for your interest in PHP.

    ..

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

    [2007-02-24 21:36:47] bruno dot boccara at d2b dot com

    Description:
    ------------
    round function gives wrong value.

    Please do not send me to
    [url]http://docs.sun.com/source/806-3568/ncg_goldberg.html[/url], you have to
    admit that this is a bug !!!!!
    if not, php CANNOT be use in production site with mathematical
    functions !!!

    Reproduce code:
    ---------------
    <?
    // 140.25*(1-(34/100)) = 92.565


    echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>";

    echo "direct = ".round (92.565, 2);echo "<br>";

    $valeur = 140.25*(1-(34/100));

    echo "value = ".round($valeur,2);echo "<br>";

    settype($valeur,"string");
    settype($valeur,"float");

    echo "value2 = ".round($valeur,2);

    ?>

    Expected result:
    ----------------
    formula = 92.57
    direct = 92.57
    value = 92.57
    value2 = 92.57

    Actual result:
    --------------
    formula = 92.56 // WRONG !
    direct = 92.57
    value = 92.56 // WRONG !
    value2 = 92.57


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40622&edit=1[/url]
    bruno dot boccara at d2b dot com Guest

Similar Threads

  1. sharedobject second round does not function :S
    By Hope1983 in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: July 1st, 07:37 PM
  2. Using the round function
    By Shmooter in forum Dreamweaver AppDev
    Replies: 0
    Last Post: April 28th, 12:56 AM
  3. #24828 [Asn->Csd]: round() function doesn't round !
    By edink@php.net in forum PHP Development
    Replies: 0
    Last Post: July 28th, 10:08 PM
  4. #24828 [Opn->Asn]: round() function doesn't round !
    By iliaa@php.net in forum PHP Development
    Replies: 0
    Last Post: July 27th, 06:25 PM
  5. #24828 [NEW]: round() function doesn't round !
    By christophe dot bidaux at netcourrier dot com in forum PHP Development
    Replies: 0
    Last Post: July 27th, 11:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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