# Thread: Rouding values to the nearest....

1. ## 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. try this:

<%

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. Hi Webber123456

Thanks so much!

Best regards

Rod from the UK

4. Nice solution and explanation, Webber123456!

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

Andrew

#### Posting Permissions

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