SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Integer division?

    Does PHP have integer division? I searched the PHP man and found no related info... If there is no built in operartor (I'll be suprised and) how would I go about doing it on my own?
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use floor(a/b)

    see the user comments in http://php.net/manual/en/language.operators.php

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recall once using a cast in my code. Something like

    $myInt = (int)(3/2); // myint will be 1

  4. #4
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went with the casting method... I was just curios if PHP had any straight int div op's... Thanx guys, and I'll go look up floor()...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  5. #5
    SitePoint Member
    Join Date
    Jan 2001
    Location
    Portland, OR
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, use bcdiv() and set scale to zero.

    see: http://www.php.net/manual/en/function.bcdiv.php
    Discogs - Building the definitive electronic music database...

  6. #6
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bcdiv() is a function and not an operator...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"


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
  •