SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2002
    Location
    New Zealand
    Posts
    1,021
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How Do You Truncate A Number?

    Hi,

    How do you truncate or round a number to a set no. of decimal places in PHP?

    eg

    16.666666666667 => 16 or 16.7

    I have looked for a truncate function and a rounding funtion but can't find one.

    Any help would be great,
    Thanks

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    round(); maybe?

  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    Melbourne, Australia
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Counter Code Enterprise Edition
    Run your own web counter/statistics service

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Serbia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so it would be
    PHP Code:
    echo round(16.66666667); 
    This will actually give you 17
    PHP Code:
    echo round(16.6666671); 
    would give you 16.7
    Wondering about best weight loss pill? Take a look at Proactol.

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2002
    Location
    New Zealand
    Posts
    1,021
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies. I don't have time to look at them right now but they look like what I need.

    Thanks


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
  •