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
Solved

Number Rounding to the Nearest 0.5

Posted on 2007-11-30
9
863 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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…

856 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