Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Number Rounding to the Nearest 0.5

Posted on 2007-11-30
Medium Priority
874 Views
I have several numbers collected from a database that I need to round.

These numbers vary from 2.444 to 2.645 and different again.

I need all number rounding to 0.5 mark, so 1.666 would be 1.5 1.444 would be 1.5 but 1.2333 would be 1.

How can I accomplish this in visual basic 6?
0
Question by:Terry Rogers
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3
• 2

LVL 55

Expert Comment

ID: 20382443
the usual trick is to multiply by 2, round, and divide by 2

0

LVL 8

Expert Comment

ID: 20382500
i no longer have vb 6 installed but there should be a function called round that will do the trick for you

greg

0

LVL 55

Expert Comment

ID: 20382550
it should be:

int(yournumber*2)/2
0

LVL 1

Author Comment

ID: 20382683
jaime_olivares:

You solution works, but not as entirely expected. A Figure of  21.77 gets rounded down to 21.5 not to 22 like it should be.
0

LVL 55

Expert Comment

ID: 20382769
ok, try with:
int((yournumber+0.5)*2)/2
0

LVL 1

Author Comment

ID: 20383129
Now, the number 21.6666666666667 gets rounded to 22 not, 21.5 as it should be. ???
0

LVL 55

Accepted Solution

Jaime Olivares earned 2000 total points
ID: 20383242
Oh, sorry, is should be:
int((yournumber+0.25)*2)/2

0

LVL 8

Expert Comment

ID: 20383262
i think you will be more accurate if you search out the vb6 math library.

greg
0

LVL 1

Author Closing Comment

ID: 31411917
Works fine now. Thanks for your help!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent â€¦
Itâ€™s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following â€¦
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrâ€¦
###### Suggested Courses
Course of the Month6 days, 22 hours left to enroll