SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rouding values to the nearest....

    Hi guys

    I'm hoping this is an easy one....

    In my asp page, how would I round up a value to the nearest 10. For example,

    995 = 1000
    1995 = 2000
    2544 = 2540
    26992 = 26990
    350996 = 350400

    How is this done? Any help would be fully appreciated

    Best regards

    Rod from the UK

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:


    <%

    'Integrated Answer

    X = 995 'number to round
    N = 10 'rounding factor

    'Beware: VB uses [Bankers Rounding], to the nearest even number, which can be surprising if you're not aware of it:

    response.write ("round(1.5)=" & cstr(round(1.5))) & "<br>" 'result to 2
    response.write ("round(2.5)=" & cstr(round(2.5))) & "<br><br>" 'yes, result to 2 too

    response.write ("X = 995 number to round")& "<br>"
    response.write ("N = 10 rounding factor")& "<br>"
    response.write ("round(X/N)*N=" & cstr(round(X/N)*N))& "<br><br>"

    X = 1995 'number to round

    response.write ("X = 1995 number to round")& "<br>"
    response.write ("N = 10 rounding factor")& "<br>"
    response.write ("round(X/N)*N=" & cstr(round(X/N)*N))& "<br><br>"

    X = 2544 'number to round

    response.write ("X = 2544 number to round")& "<br>"
    response.write ("N = 10 rounding factor")& "<br>"
    response.write ("round(X/N)*N=" & cstr(round(X/N)*N))& "<br><br>"

    X = 26992 'number to round

    response.write ("X = 26992 number to round")& "<br>"
    response.write ("N = 10 rounding factor")& "<br>"
    response.write ("round(X/N)*N=" & cstr(round(X/N)*N))& "<br><br>"

    X = 350996 'number to round

    response.write ("X = 350996 number to round")& "<br>"
    response.write ("N = 10 rounding factor")& "<br>"
    response.write ("round(X/N)*N=" & cstr(round(X/N)*N))& "<br><br>"


    %>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2014
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Webber123456

    Thanks so much!

    Best regards

    Rod from the UK

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,030
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Nice solution and explanation, Webber123456!

    I didn't know about "Bankers Rounding" but I've experienced it and been surprised.

    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


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
  •