RE: Rounding Numbers

1. Senior Member
Join Date
Dec 1969
Posts
223

## RE: Rounding Numbers

Hi, is there a function that allows me to round numbers to <BR>the nearest number divisible by 25. Ex: I want to round <BR>583 to 575 and 677 to 675. or 690 to 700, etc.<BR>

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## Code it

Function RndToTwentyFive(num)<BR><BR> If num % 25 = 0 Then<BR> RndToTwentyFive = num<BR> Else<BR> If num % 25 &#060; 12 Then<BR> RndToTwentyFive = num - (num % 25)<BR> Else<BR> RndToTwentyFive = num + (num % 25)<BR> End If<BR> End If<BR>End Function<BR><BR>Off the top of my head... probably errors somewhere but should get ya going.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## Easy to write your own:

&#060;%<BR>Function RoundTo( num, roundat )<BR> RoundTo = roundat * Round( num / roundat )<BR>End Function<BR>%&#062;<BR><BR>See how it works? Let&#039;s take 690 as an example:<BR> 690 / 25 --&#062;&#062; 27.6<BR> Round( 27.6 ) --&#062;&#062; 28<BR> 28 * 25 --&#062;&#062; 700<BR><BR>Simple math, no?<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## Tch! **** one line functions...

Mine looks more complicated, so nyah.<BR><BR>Forgot all about Round() &#060;snaps finger&#062;

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Ummm...DG...what does % mean?

In VBScript?<BR><BR>You been working in Java/C/C++/JavaScript too long?<BR><BR>And don&#039;t you mean "&#060; 12.5" ??? Assuming that % will return a non-integer? (If it doesn&#039;t, it&#039;s worthless for this purpose, isn&#039;t it?)<BR><BR>Anyway, even in JS code, that&#039;s too complex:<BR> function RoundTo( num, roundat )<BR> {<BR> return roundat * Math.round( num / roundat );<BR> }<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
223

## RE: Tch! **** one line functions...

Thanks Guys, Dont worry Ghost, I&#039;m the lazyass that was looking for some function and didnt even know it was so easy to do it myself already.

7. Senior Member
Join Date
Dec 1969
Posts
11,334

## Heh

I thought % was shorthand for the Mod() operator in VBS... maybe it was a C thing.<BR><BR>I thought about 12.5, but wanted to keep it easier (talking out my *** now)<BR><BR>Argh. I feel like a newbie again at times looking at some code that gets posted here anymore....<BR><BR>Regardless, my multiple if statement isn&#039;t as pretty as yours, so it&#039;s all moot at this point :)

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Did you see this one?

http://www.aspmessageboard.com/forum/asp.asp?M=494724&T=494662&F=20&P=1<BR><BR>Now *THAT* puts me well and truly in my place! The kind of thing I wish I had written!<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## Heh, yeah, and a oh crap

I agree with you though... readability and maintainability is more important in every case... probably 99.5% (for my saying, "If you&#039;re that worried about speed, ya ain&#039;t using ASP)<BR><BR>Check this out<BR><BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=117<BR><BR>Can you fix that one?????? I don&#039;t have modify privies (at least I haven&#039;t tried in 2 years). Funny, nearly 15,000 people read that and not one complaint about it not working with the %.<BR><BR>I have to test it to see if it works... I find it difficult to believe no one complained about that to me (since they complain about every other typo in every other FAQ)... <BR><BR>I think it&#039;s soon time for me to go out to the old ASP pasture... :)

10. Senior Member
Join Date
Dec 1969
Posts
11,334

## Nope, it's broke

And funny enough.... you modified that FAQ in the past as well :)<BR><BR>So we&#039;re both losing it when looking at % symbols... sigh.

#### Posting Permissions

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