Divide variables

Discussion in 'PHP' started by johneva, Mar 18, 2011.

  1. #1
    Hi all

    I know its simple to divide variable but what do I need to add so it only shows the result to 1 decimal place?

    For example

    	echo 'Rating ' . $rating/$votes;
    PHP:
    Dont matter found it.

    	echo 'Rating ' . round($rating/$votes,1);
    PHP:
     
    Last edited: Mar 18, 2011
    johneva, Mar 18, 2011 IP
  2. Minimal Hank

    Minimal Hank Peon

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    number_format() is the way to go.
     
    Minimal Hank, Mar 18, 2011 IP
  3. srisen2

    srisen2 Peon

    Messages:
    359
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could use substr too
     
    srisen2, Mar 18, 2011 IP
  4. rockowtham

    rockowtham Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi,
    number_format($rating/$votes,1);
    i hope this would give you a SOLUTION.
     
    rockowtham, Mar 21, 2011 IP
  5. vediovis

    vediovis Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    number_format is your friend
     
    vediovis, Mar 22, 2011 IP