Thread: Divide in php

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    2

    Divide in php


    Hi,

    I have a value as $total = 2.4567 ;
    How can I see only only 2? I don't want to round up. I just
    want to see the value before the decimal point.

    Example: i want to see only as 1 in below. How can i do that?

    PHP Code:
    $a ;
    $b ;
    $total $a/$b ;
    echo 
    $total 
    Thanks.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    90
    Rep Power
    77
    Here's what you want and mean....

    PHP Code:
    $a 3;
    $b 2;

    echo 
    $c $a $b;
    echo 
    "<br />";
    echo 
    floor($c); // rounds down to 1
    echo "<br />"
    echo 
    ceil($c// rounds up to 2 
    echo "...or...<br />";
    echo 
    intval($c); 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    2
    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo