SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2000
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    A part of my PHP script gets the average user rating of something from the database, and prints it out. This works without a hitch, but there is sometimes a rating like 86.666 after being averaged. I'm wondering how I can get only the value before the decimal, and nothing after. I know this can be done using both split() and regex() functions, but my attempts at getting this working always fail.

    Example:
    Code:
    list ($percent, $unwanted) = split("[.]", $average);
    Doesn't work. I'm sure there is a really simple way of doing this, but I'm not sure what it is

    Andrew.

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are several ways to do this:

    - number_format($number,0);
    - $num = floor($num);
    - $num = (int)$num;
    .....

    Using reg. expression here is an overkill!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


Bookmarks

Posting Permissions

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