ROUNDING A NUMBER TO THE NEAREST 5

# Thread: ROUNDING A NUMBER TO THE NEAREST 5

1. Junior Member
Join Date
Dec 1969
Posts
2

## ROUNDING A NUMBER TO THE NEAREST 5

dear all, my programming / maths skills are not good so i seek your help! <BR><BR>i have made a script which returns a number, but i need to round this number to the nearest 5, eg if the number is 3.27 it needs to round to 5, if it was 14.1 it would round to 15.<BR><BR>i&#039;ve consulted the MSDN but to no avail so please help!<BR><BR>thanks in advance,<BR><BR>harry<BR><BR>

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

## Easy enough...

Divide by 5, round to nearest 1, Multiply by 5.<BR><BR>&#060;%<BR>Function RoundTo5( num )<BR> RoundTo5 = 5 * Round( num / 5 )<BR>End Function<BR>%&#062;<BR><BR>Try it: <BR>3.27 / 5 --&#062;&#062; 0.654 --&#062;&#062; rounded to 1 becomes 1 --&#062;&#062; times 5 is 5.<BR><BR>14.1 / 5 --&#062;&#062; 2.82 --&#062;&#062; rounded to 1 becomes 3 --&#062;&#062; time 5 is 15.<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
2

## Thank you!

Dear Bill,<BR><BR>Many thanks for this, I feel stupid for not being able to work it out myself!<BR><BR>Thanks again,<BR><BR>Harry

#### Posting Permissions

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