Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts

    Question Recurring number eg . 1.3333333 How do i make it to 2 decimal places HELP

    how would i make the recurring number to 2 decimal places eg . 1.33 or even 0 decimal places eg 1

    Image to see problem
    PHP Code:
    $burgans08 = (($burg08 $burg07) * 100)-100;
    $stabans08 = (($stab08 $stab07) * 100)-100;

    echo 
    "<div class='answercont'>";
    if(
    $burgans08<0){
        echo 
    "<div id='ansburg08'><b>" .$burgans08"%</b> Decrease in burglary since 2007</div>";
        }
    if(
    $burgans08>0){
        echo 
    "<div id='ansburg08'><b>" .$burgans08"%</b> Rise in burglary since 2007</div>";
        }
    if(
    $burgans08==0){
        echo 
    "<div id='ansburg08'><b>" .$burgans08"%</b> Burglary is the same since 2007</div>";
        } 
    $burgans08
    $stabans08

    those variable are givind me the answer to the equation so how would i format the answer to 2 decimal places eg . 1.33 or even 0 decimal places eg 1

    Max
    Last edited by maxvee8; 03-17-2008 at 02:03 AM.
    "I have not failed, I've found 10,000 ways that don't work" Thomas Edison

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    echo round("1.33333",2);
    echo 
    round("1.66666",3); 
    not tested,

    http://www.php.net/manual/en/function.round.php

    best regards

  • Users who have thanked oesxyl for this post:

    maxvee8 (03-17-2008)

  • #3
    Regular Coder maxvee8's Avatar
    Join Date
    Feb 2008
    Location
    UK
    Posts
    185
    Thanks
    19
    Thanked 18 Times in 18 Posts
    ok that worked thanks
    "I have not failed, I've found 10,000 ways that don't work" Thomas Edison


  •  

    Posting Permissions

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