Print Page | Close Window

Round Function

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7857
Printed Date: 01 April 2026 at 12:59am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Round Function
Posted By: fark
Subject: Round Function
Date Posted: 04 December 2003 at 10:50am
I need to round up by 5's.  Is there already a function to do that or do I have to write my own?  Any idea how I would write my own?  Thanks.



Replies:
Posted By: zaboss
Date Posted: 04 December 2003 at 11:02am
All the asp functions you need are http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtorifunctions.asp - here . I think you'll have to use Round.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: ljamal
Date Posted: 04 December 2003 at 12:29pm
Round only rounds up or down to the decimal space you desire which means is rounds to base 10 (1,10,100 etc). To round up by 5 you will need to use the modulus operator and create your own function

Function RoundUpBy5(intValue)
if IsNumeric(intValue) then
if intValue mod 5 > 0 then
     intValue=intValue+(5-intValue mod 5)
end if
RoundUpBy5 = intValue
else
RoundUpBy5 = "Value is not numeric"
end if
End Function

The function above should round up by 5. If you are looking to round to the nearest number divisible by five use the function below.

Function RoundNearest5(intValue)
if IsNumeric(intValue) then
if intValue mod 5 > 2 then
     intValue=intValue+(5-intValue mod 5)
else
     intValue=intValue-intValue mod 5
end if
RoundNearest5 = intValue
else
RoundNearest5 = "Value is not numeric"
end if
End Function


-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: fark
Date Posted: 05 December 2003 at 7:19am

Thanks for your help!

I didn't see the mod function at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtorifunctions.asp - http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/script56/html/vtorifunctions.asp  so I'm really glad you mentioned it.

I changed the line intValue=intValue+(5-intValue mod 5)  to be intValue = ((Int(intValue/5)) * 5) + 5 for my purposes.  The function works wonderfully!  Thanks for everyones help.



Posted By: ljamal
Date Posted: 05 December 2003 at 9:22am
Mod is considered an mathematical operator (like +,-,*,/) that is why it's not found amongst the function.



-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net