Professional Web Applications Themes

#40924 [NEW]: round() precision problem - PHP Bugs

From: info at e-mhd dot com Operating system: Win & Linux PHP version: 5.2.1 PHP Bug Type: Performance problem Bug description: round() precision problem Description: ------------ Problem with function round() rounded value is incorrect Reproduce code: --------------- ini_set("precision", 15); bcscale(5); $a1 = (string)(3845349 * 34.065); $a2 = (float)(3845349 * 34.065); $a3 = bcmul(3845349, 34.065); echo "A1 = "; var_dump($a1); echo("<br />"); echo "A2 = "; var_dump($a2); echo("<br />"); echo "A3 = "; var_dump($a3); echo "<br />Values after round() :"; echo "<br />A1 = ".round( $a1 ,2); echo "<br />A2 = ".round( $a2 ,2); echo "<br />A3 = ".round( $a3 ,2); ...

  1. #1

    Default #40924 [NEW]: round() precision problem

    From: info at e-mhd dot com
    Operating system: Win & Linux
    PHP version: 5.2.1
    PHP Bug Type: Performance problem
    Bug description: round() precision problem

    Description:
    ------------
    Problem with function round()
    rounded value is incorrect

    Reproduce code:
    ---------------
    ini_set("precision", 15);
    bcscale(5);
    $a1 = (string)(3845349 * 34.065);
    $a2 = (float)(3845349 * 34.065);
    $a3 = bcmul(3845349, 34.065);
    echo "A1 = ";
    var_dump($a1);
    echo("<br />");
    echo "A2 = ";
    var_dump($a2);
    echo("<br />");
    echo "A3 = ";
    var_dump($a3);
    echo "<br />Values after round() :";
    echo "<br />A1 = ".round( $a1 ,2);
    echo "<br />A2 = ".round( $a2 ,2);
    echo "<br />A3 = ".round( $a3 ,2);

    Expected result:
    ----------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.69
    A3 = 130991813.69

    Actual result:
    --------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.68
    A3 = 130991813.69

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

  2. #2

    Default #40924 [Opn->Bgs]: round() precision problem

    ID: 40924
    Updated by: net
    Reported By: info at e-mhd dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Performance problem
    Operating System: Win & Linux
    PHP Version: 5.2.1
    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:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

    Thank you for your interest in PHP.

    ..


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

    [2007-03-26 16:52:36] info at e-mhd dot com

    Description:
    ------------
    Problem with function round()
    rounded value is incorrect

    Reproduce code:
    ---------------
    ini_set("precision", 15);
    bcscale(5);
    $a1 = (string)(3845349 * 34.065);
    $a2 = (float)(3845349 * 34.065);
    $a3 = bcmul(3845349, 34.065);
    echo "A1 = ";
    var_dump($a1);
    echo("<br />");
    echo "A2 = ";
    var_dump($a2);
    echo("<br />");
    echo "A3 = ";
    var_dump($a3);
    echo "<br />Values after round() :";
    echo "<br />A1 = ".round( $a1 ,2);
    echo "<br />A2 = ".round( $a2 ,2);
    echo "<br />A3 = ".round( $a3 ,2);

    Expected result:
    ----------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.69
    A3 = 130991813.69

    Actual result:
    --------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.68
    A3 = 130991813.69


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


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

  3. #3

    Default #40924 [Bgs->Csd]: round() precision problem

    ID: 40924
    User updated by: info at e-mhd dot com
    Reported By: info at e-mhd dot com
    -Status: Bogus
    +Status: Closed
    Bug Type: Performance problem
    Operating System: Win & Linux
    PHP Version: 5.2.1
    New Comment:

    Thank you for your reply.


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

    [2007-03-26 17:11:02] net

    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:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

    Thank you for your interest in PHP.

    ..

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

    [2007-03-26 16:52:36] info at e-mhd dot com

    Description:
    ------------
    Problem with function round()
    rounded value is incorrect

    Reproduce code:
    ---------------
    ini_set("precision", 15);
    bcscale(5);
    $a1 = (string)(3845349 * 34.065);
    $a2 = (float)(3845349 * 34.065);
    $a3 = bcmul(3845349, 34.065);
    echo "A1 = ";
    var_dump($a1);
    echo("<br />");
    echo "A2 = ";
    var_dump($a2);
    echo("<br />");
    echo "A3 = ";
    var_dump($a3);
    echo "<br />Values after round() :";
    echo "<br />A1 = ".round( $a1 ,2);
    echo "<br />A2 = ".round( $a2 ,2);
    echo "<br />A3 = ".round( $a3 ,2);

    Expected result:
    ----------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.69
    A3 = 130991813.69

    Actual result:
    --------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.68
    A3 = 130991813.69


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


    --
    Edit this bug report at http://bugs.php.net/?id=40924&edit=1
    info Guest

  4. #4

    Default #40924 [Csd->Bgs]: round() precision problem

    ID: 40924
    Updated by: net
    Reported By: info at e-mhd dot com
    -Status: Closed
    +Status: Bogus
    Bug Type: Performance problem
    Operating System: Win & Linux
    PHP Version: 5.2.1


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

    [2007-03-28 13:35:42] info at e-mhd dot com

    Thank you for your reply.

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

    [2007-03-26 17:11:02] net

    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:
    http://docs.sun.com/source/806-3568/ncg_goldberg.html

    Thank you for your interest in PHP.

    ..

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

    [2007-03-26 16:52:36] info at e-mhd dot com

    Description:
    ------------
    Problem with function round()
    rounded value is incorrect

    Reproduce code:
    ---------------
    ini_set("precision", 15);
    bcscale(5);
    $a1 = (string)(3845349 * 34.065);
    $a2 = (float)(3845349 * 34.065);
    $a3 = bcmul(3845349, 34.065);
    echo "A1 = ";
    var_dump($a1);
    echo("<br />");
    echo "A2 = ";
    var_dump($a2);
    echo("<br />");
    echo "A3 = ";
    var_dump($a3);
    echo "<br />Values after round() :";
    echo "<br />A1 = ".round( $a1 ,2);
    echo "<br />A2 = ".round( $a2 ,2);
    echo "<br />A3 = ".round( $a3 ,2);

    Expected result:
    ----------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.69
    A3 = 130991813.69

    Actual result:
    --------------
    A1 = string(13) "130991813.685"
    A2 = float(130991813.685)
    A3 = string(13) "130991813.685"
    Values after round() :
    A1 = 130991813.69
    A2 = 130991813.68
    A3 = 130991813.69


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


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

Similar Threads

  1. Serious round() problem
    By ldetant2 in forum Macromedia ColdFusion
    Replies: 7
    Last Post: June 24th, 09:22 PM
  2. #24876 [NEW]: Round does not round properly
    By jeff at tmtrading dot com in forum PHP Development
    Replies: 0
    Last Post: July 30th, 11:57 PM
  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