Link to home
Start Free TrialLog in
Avatar of Terry Rogers
Terry RogersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Number Rounding to the Nearest 0.5

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?
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

the usual trick is to multiply by 2, round, and divide by 2

Avatar of Autoeforms
Autoeforms

i no longer have vb 6 installed but there should be a function called round that will do the trick for you

greg

it should be:

int(yournumber*2)/2
Avatar of Terry Rogers

ASKER

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.
ok, try with:
int((yournumber+0.5)*2)/2
Now, the number 21.6666666666667 gets rounded to 22 not, 21.5 as it should be. ???
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think you will be more accurate if you search out the vb6 math library.

greg
Works fine now. Thanks for your help!