Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Round Function
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Round Function

 Post Reply Post Reply
Author
fark View Drop Down
Newbie
Newbie


Joined: 04 November 2003
Location: United States
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote fark Quote  Post ReplyReply Direct Link To This Post Topic: Round Function
    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.
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 04 December 2003 at 11:02am
All the asp functions you need are here. I think you'll have to use Round.
Cristian Banu
Soft 4 web
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
fark View Drop Down
Newbie
Newbie


Joined: 04 November 2003
Location: United States
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote fark Quote  Post ReplyReply Direct Link To This Post 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/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.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 05 December 2003 at 9:22am
Mod is considered an mathematical operator (like +,-,*,/) that is why it's not found amongst the function.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.