how do I round a count to the nearest...

# Thread: how do I round a count to the nearest...

1. Junior Member
Join Date
Dec 1969
Posts
8

## how do I round a count to the nearest...

number divisible by ten. I have a count like "12" and I would like to round that up to the nearest 10th. In this case, the resulting answer would be "20"

2. Senior Member
Join Date
Dec 1969
Posts
373

## RE: how do I round a count to the nearest...

Don&#039;t know if this is the best way for you but here:<BR><BR>&#039;Get the last number<BR><BR>num = urVar mod 10<BR><BR>num = 10 - num<BR><BR>urVar = urVar + num<BR><BR>In this case urVar would be the number you want to round up.

3. Junior Member
Join Date
Dec 1969
Posts
8

## RE: how do I round a count to the nearest...

thanks.<BR><BR>I just found that this way works too...<BR><BR>Round(urVar / 10) * 10

4. Senior Member
Join Date
Dec 1969
Posts
373

## Actually...

That will only work on numbers that their last number is over 5, numbers like 16, 39...<BR><BR>But it will not work on 12, 12 will result in 10 after your code.

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

## Doesn't work.

&nbsp;<BR>urvar = 30 &#039; initial condition<BR>num = urvar MOD 10 &#039; num is zero<BR>num = 10 - num &#039; num is now 10<BR>urvar = urvar + num &#039; urvar is now 40!<BR><BR>*********<BR><BR>You *could* fix this by changing the next to last step:<BR><BR>If num &#060;&#062; 0 Then num = 10-num<BR><BR>There are various other ways to do this, but this isn&#039;t bad.<BR><BR>

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

## agreed <eom>

.

7. Senior Member
Join Date
Dec 1969
Posts
373

Ok so here is the *Fixed* version:<BR><BR>num = urVar mod 10<BR><BR>if num &#060;&#062; 0 then<BR> num = 10 - num<BR> urVar = urVar + num<BR>end if<BR>

8. Junior Member
Join Date
Dec 1969
Posts
8

## RE: My Bad...

thanks fellas.

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

## So to do it all in one line:

urVar = urVar - CLng((urVar MOD 10) &#060;&#062; 0) * (10 - (urVar MOD 10))<BR><BR>Heh. Sneaky?<BR><BR>

#### Posting Permissions

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