SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I remove decimals in PHP?

    Say that I have a variable that outputs a number such as:
    17.672

    I would prefer the number to display as "17"

    Rather than rounding, how would I remove the decimal notation from this number?

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    floor(17.672); 
    floor() makes it stay as a float, so mark's solution below (same as intval(17.672) ) might be better.

  3. #3
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo (int)17.672

  4. #4
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo round(10.5); // Round the number, this example would echo 11.
    echo '<br />';
    echo 
    floor(10.5); // Round down, this would echo 10.
    echo '<br />';
    echo 
    ceil(10.3); // Round up, this would be 11. 

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys


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
  •