Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ROUNDING NUMBERS IN VB6.0 1

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
Using the Round function in VB6.0.
The Round function wants to round up to only the next even number. Example: Round(15.545,2) rounds to 15.54
Round(15.555,2) rounds to 15.56
I need to round to the next number regardless of whether its even or odd. Example:
need Round(15.545,2) to round to 15.55
I am using Currency data type but doesn't seem to matter what data type I use.
I am doing currency calcs in payroll and always need to give the employee the .5 cents as an extra penny which adds up over a period of hours and time.

Any help or suggestions is appreciated.

TNN, Tom
TNPAYROLL@AOL.COM

TOM
 
Hi,

This should work:

MyroundNum=format(MyNum,"0.00")

Format always rounds 5 upwards, whereas round() rounds up or down depending on if the number is even or odd, to make sure that you do not get a statistical offset.

Sunaj


 
Sunaj,

Thank You. That Format function did the trick. I was not aware that the Format function did any rounding.

Now that I have exposed my ignorence may I ask, What is a "stastical offset"? I didn't take statistics in school.

Don't bother if the answer is involved. Don't want to take your time.

Thank You again.
TNN, Tom
TNPAYROLL@AOL.COM

TOM
 
Hi,

If you do a lot of calculations and allways rounds .5 upwards, the average of your rounded numbers will be larger than the average of the unrounded numbers. Therefore VB rounds even numbers upwards and and odd numbers downwards(or is it the otherway around?), this ensures that the average in the long run remians the same.

Sunaj
 
Hi;

For a good overview of custom rounding procedures in VB 5 & 6 reference Support KB Q196652 Title HOWTO: Implement Custom Rounding Procedures. Rounding has not been implemented the same across the various Microsoft products.

Cloudmar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top