Terry Rogers
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?
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?
the usual trick is to multiply by 2, round, and divide by 2
i no longer have vb 6 installed but there should be a function called round that will do the trick for you
greg
greg
it should be:
int(yournumber*2)/2
int(yournumber*2)/2
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.
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
int((yournumber+0.5)*2)/2
ASKER
Now, the number 21.6666666666667 gets rounded to 22 not, 21.5 as it should be. ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i think you will be more accurate if you search out the vb6 math library.
greg
greg
ASKER
Works fine now. Thanks for your help!