SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    grabbing decimal only

    Hello,

    I need to take just the decimal from a value. For example if I have 21.5. I need the page to tell me only the .5. Does anyone know a simple way to do this? I was thinking about using:

    PHP Code:
    substr($value, -22

    to get only the last 2 characters in the number but I'm not sure if that will work on integer values.

    Thanks.

    UPDATE: Actually using subsr() did work.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $num = 1.2345;
    
    $frac = $num % 1;


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
  •