SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Fractions in PHP

    Hi,
    I am trying to put together a page which calculates postage fo an order.

    The rules are that for every five items or less postage costs $5.

    Therefore if you buy 7 items postage is $10.
    Is anyone please able to tell me if their is a function in PHP to identify the whole number and the remainder of a division?

    thank you,
    Darren.

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Try this

    PHP Code:
    $items 7;
    $postage 5;
    $totalpostage ceil($items 5) * $postage
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $cost=ceil($items/5)*5;
    $remainder $items%5
    % is the operator for the modulus (remainder) function.

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SLTP_Spencer View Post
    PHP Code:
    $cost=ceil($items/5)*5;
    $remainder $items%5
    % is the operator for the modulus (remainder) function.
    I couldnt personally see why the OP was interested in the remainder, since it serves no purpose in the problem he described, perhaps when the OP returns we'll find out why he was asking for the remainder
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


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
  •