Solved

Number Rounding to the Nearest 0.5

Posted on 2007-11-30
9
860 Views
Last Modified: 2010-04-21
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
Comment
Question by:Terry Rogers
  • 4
  • 3
  • 2
9 Comments
 
LVL 55

Expert Comment

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

0
 
LVL 8

Expert Comment

by:Autoeforms
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

by:Jaime Olivares
ID: 20382550
it should be:

int(yournumber*2)/2
0
 
LVL 1

Author Comment

by:Terry Rogers
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20382769
ok, try with:
int((yournumber+0.5)*2)/2
0
 
LVL 1

Author Comment

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

Accepted Solution

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

0
 
LVL 8

Expert Comment

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

greg
0
 
LVL 1

Author Closing Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now