PHP Round

Discussion in 'PHP' started by adamjthompson, Jun 18, 2007.

  1. #1
    I need to round a number to two decimal places. Here's the code. What is the correct code to round to two decimal places?

    $ctr= round(($row['number_clicks']/$row['impression'])*100) . "%";
    PHP:
    Thanks!

    ~Adam
     
    adamjthompson, Jun 18, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Click on the link in your code. :D

    
    $ctr= round(($row['number_clicks']/$row['impression'])*100, 2) . "%";
    
    PHP:
     
    nico_swd, Jun 18, 2007 IP
  3. adamjthompson

    adamjthompson Well-Known Member

    Messages:
    1,242
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Ah, thanks...somehow I missed that info in the manual the first time I read it.

    else $ctr= round(($row['number_clicks']/$row['impression'])*100, 2) . "%";
    PHP:
     
    adamjthompson, Jun 18, 2007 IP
  4. Evoleto

    Evoleto Well-Known Member

    Messages:
    253
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    Sometimes number_format can be useful too. I use it to format currencies and percentages too.

    Good luck!
     
    Evoleto, Jun 18, 2007 IP