SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How do i get the decimal part of a division?

    Hello,

    How does on get in PHP the decimal of a division?
    That is say you divide 110/30 the result is 3.667


    How does one get the 0.667 part of the above number?



    Regards,

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $x 110 30;
    $decimal_part $x floor($x); 
    Although, you may want to take a look at the modulo operator:
    PHP Code:
    $x 110 30

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ThanX. This works fine.
    Have a great day


    Quote Originally Posted by kyberfabrikken View Post
    PHP Code:
    $x 110 30;
    $decimal_part $x floor($x); 
    Although, you may want to take a look at the modulo operator:
    PHP Code:
    $x 110 30

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Another example, casting to an integer instead of calling the float function.
    PHP Code:
    $result 110 30;
    $decimal $result - (int) $result
    Salathe
    Software Developer and PHP Manual Author.


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
  •