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)

    dealing with fractions

    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/Javasrcipt to identify the whole number and the remainder of a division?

    thank you,
    Darren.

  2. #2
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    postageCost = Math.floor(itemCount / 5) * 5;

    Cheers,
    D.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Math.ceil(num/5)*5

  4. #4
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ROFL! Yes, ceil() would be better.

    Cheers,
    D.


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
  •