Solved

Number Rounding to the Nearest 0.5

Posted on 2007-11-30
9
861 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

19 Experts available now in Live!

Get 1:1 Help Now