Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Number Rounding to the Nearest 0.5

Posted on 2007-11-30
9
Medium Priority
?
881 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 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