www.webdeveloper.com
Results 1 to 5 of 5

Thread: Rounding Numbers

  1. #1
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    969

    Rounding Numbers

    I don't think there is a current method to do this, but what I need to do is, round an integer(not decimal) to the nearest 5(or basically a number other than 1).

    For instance I have a 37 from an equation, and i want to round it to 35, because it is the nearest 5. If it were a 38, it would round to 40.

    And thoughts on how to do this? Thanks in advance.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    just do some simple maths
    Code:
    <input type="text" onChange="alert(Math.round(this.value / 5) * 5);">

  3. #3
    Join Date
    Jan 2005
    Posts
    3,067
    Math.round --> round to nearest whole number
    Math.floor --> round down to whole number

  4. #4
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    Quote Originally Posted by konithomimo
    Math.round --> round to nearest whole number
    Math.floor --> round down to whole number
    sorry i missed your point.

  5. #5
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    You cannot mention Math.floor without Math.ceil
    Code:
    <script type="text/javascript">
    alert(Math.ceil(2.00000001));//3
    alert(Math.floor(3.99999999));//3
    alert(Math.round(2.5));//3
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles