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

Financial rounding 1

Status
Not open for further replies.

SBerthold

Programmer
Sep 20, 2002
1,014
DE
Who has a correct formula to financial round with?
(regardless if the number is positive, negative, whole, fractional)

The Function needs to work like the VB Round function.

I have yet to find one, or create a way that is correct, but still reasonably fast.
 
Excellent!

It's fast (the function in last post) and works when you take the following into consideration:

There seems to be a problem with the CDbl or using a double variable, as mentioned in thread356567.

RoundF(4.989195 ,5) rounds to 4.98919 and not 4.98920.

The only thing that seems to work is to use Singles/CSng, Currency/CCur or CDec, the last 2 being most accurate with-in their the ranges you mentioned, and the Single being also good but cannot use with extremely small/large numbers.

The only answer there seems to be is to use a Single variable or the CSng functions, or, if the number is small enough, then use CCur or a currency variable, or the CDec function.

However, the request is for financial rounding. So, the number of digits should not be that much, and, if it is a financial class or proceedure or even application, then it would seem fitting to always use Currency variables for currency figures.

In the case of rounding non-currency values, I think the use of a Single is good enough for rounding. If you are working with very small numbers, then you have no choice but to use a Double.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top