I want to be able to take numbers like the following (108.33333333333) and strip out everything to the right of the decimal point, including the decimal point. The numbers can vary from two digits on the left of the decimal point to 4 numbers to the left of the decimal point.

Can anyone suggest a method? It is the variable amount of numbers to the left that is throwing me off.

Any suggestions will be greatly appreciated! Thanks.

Alan

    All you have to do is use the round() function.

    round(108.3333333333, 0)
    would return
    108

    I believe you can also use the floor() function.

    Bryce

      do something like this:
      $myvar = 108.333333333333

      explode(".", $myvar);

      That will put the number into an array like this: So the first part of the array is 108, and the second part of the array is 333333333333. So just do this:

      echo $myvar[0]; //this will echo 108

      Hope this helps!

      Jason Rottman
      Webmaster
      Project Manager
      www.stardefenders.com

        How about using settype...

        $value = 108.3333333;
        settype($value, "integer");

        echo $value; // will return 108

          the round() function was just what I needed. It worked perfectly. Thanks everyone for your suggestions!

          Alan

            Write a Reply...