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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round Function

Status
Not open for further replies.

devnull69

Programmer
Jun 25, 2002
10
DE
Hi there,

as far as you didn't already know: The use of the function ROUND is essentially different in both VB and VBA. VB's round function performs the rounding mathematically, VBA performs it mercantilistic.

Example:

VB : Round(1.125,2) = 1.12 !!
VB : Round(1.126,2) = 1.13
VB : Round(1.135,2) = 1.14

VBA: Round(1.125,2) = 1.13 !!
VBA: Round(1.126,2) = 1.13
VBA: Round(1.135,2) = 1.14

So in VB you better use the Format function for the proper rounding.
 
Hi devnull69,

If you Try:-

Round(1.135, 2) you will get 1.14

This is because Microsft's Round Function Rounds Up for ODD Numbers (1.13) and Rounds Down for EVEN Numbers (1.12) in this Scenario.

I believe its done be design to preserve the mean (average) when Round is applied to a collection of values.


Codefish
 
You speak of "Microsoft's Round Function" ... but there is NO single consistent Round Function in different Microsoft VB/VBA products. As I pointed out before, Access97/VBA always gives 1.13 and VB6 or even Access2000 gives 1.12 ... that's a real pity, espacially when you think of upgrading your (commercial) Access application from 97 to 2000 ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top