Solved

Number Rounding to the Nearest 0.5

Posted on 2007-11-30
9
868 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
[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
  • Learn & ask questions
  • 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
Industry Leaders: 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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