SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple math script divide and then round up 1 integer

    I need a simple javascript that will take a user-inputted number and then divide it by 900 and round up to the next integer.

    For example, a customer wants 2000 units and we sell units in packages of 900. So the customer would type in 2000 in a box and press "submit" and a result would be displayed notifying them to purchase 3 boxes. (2000/900 = 2.22 and since we don't break up boxes, they would need to purchase 3 full boxes)

    (Exception to rounding up... Obviously if the customer wanted a perfect factor of 900, I wouldn't need to round up an integer... if the customer ordered 1800 they would need 2 boxes)

    Help???

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var boxes = Math.ceil(quantity / 900);


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
  •