473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pennies problem

Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards
Jun 23 '06 #1
8 2005
John wrote:
Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards


Instead of discussing the ways of reducing roundoff error I'll try
calculating the tax the way my favorite waitress does it. If she
charges too much tax she'll get in trouble. If she charges too little
it comes out of her pocket. So she's very careful to get the pennies
correct :-).

Suppose the tax is 8% and the tax table the waitress uses looks
something like:

tblTaxTable
TTID AutoNumber
CentAmount Integer
CentsTax Integer
TTID CentAmount CentsTax
1 0 0
2 12 1
3 25 2
4 37 3
5 50 4
6 62 5
7 75 6
8 87 7

There's a small stack of receipts at the cash register.

tblAmountsToTax
TAID AutoNumber
AmountToTax Currency
TAID AmountToTax
1 $32.52
2 $22.99

Sample Calculation:

Tax on $32.52

32 * 8% + 4 cents on $0.52 from the table = $2.56 + $0.04 = $2.60

since 52 is >= 50 and < 62.

qryCalculateTax:
SELECT 8 AS TaxPct, [AmountToTax], CCur((Int([AmountToTax]) * [TaxPct]
+ (SELECT Last(A.CentsTax) FROM tblTaxTable AS A WHERE A.CentAmount <=
100 * (tblAmountsToTax.AmountToTax -
Int(tblAmountsToTax.AmountToTax)))) / 100) AS theTax FROM
tblAmountsToTax;

!qryCalculateTax:
TaxPct AmountToTax theTax
8 $32.52 $2.60
8 $22.99 $1.83

The query calculates the tax on the dollar amount, then looks up the
remainder of the tax using tblTaxTable via a subquery.

James A. Fortune
CD********@FortuneJames.com

Jun 23 '06 #2
Have you tried the Round function in Access?
Round([Net] * [TaxRate] / 100 + .0001 , 2)
The additional .0001 compensates for the round to even functionality
included in the Access Round function. The round to even functionality
causes Access to round .135 to .14 and .145 to .14 instead of the .15 that
you might expect.

Later,
David

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:7c********************@pipex.net...
Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards

Jun 23 '06 #3
I found the following:

As a point of historical interest, does anyone know how this came to be

called "Bankers' rounding"? I have yet to find any evidence that
bankers have ever rounded in this fashion.

There's a note on Bankers Rounding in this article.

HOWTO: Implement Custom Rounding Procedures
http://support.microsoft.com/default...;EN-US;Q196652

Here's a quick copy...
When you add rounded values together, always rounding .5 in the same
direction results in a bias that grows with the more numbers you add
together. One way to minimize the bias is with banker's rounding.

Banker's rounding rounds .5 up sometimes and down sometimes. The
convention
is to round to the nearest even number, so that both 1.5 and 2.5 round
to 2,
and 3.5 and 4.5 both round to 4. Banker's rounding is symmetric.

Further note:

Access and VBA perform "Bankers Rounding"

Excel does NOT.

Jun 23 '06 #4
* Ron2006:
I found the following:

As a point of historical interest, does anyone know how this came to be

called "Bankers' rounding"? I have yet to find any evidence that
bankers have ever rounded in this fashion.

I have no idea if there is any truth to it or not, but I heard a long
time ago that some clever programmer in a banking environment found a
way to route all rounding errors into his own bank account. He was
eventually found out and a policy was activated at the institution that
required "bankers rounding" that was intended to prevent someone from
doing it again.

Bankers rounding is practiced in any statistical analysis environment
where a large sample of input data are used. Always rounding x.5 to x+1
would distort the result if many millions of computations were involved.
2.5 is no closer to 3 than it is to 2.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jun 24 '06 #5
I worked for a S&L on mainframe with cobol and there was not such thing
as bankers rounding. And I heard the same story. We often joked about
how it could be done.

True or not, I have no idea. But never worth it.

Take care.

Ron

Jun 26 '06 #6
Hi John

Did you find an answer to the problem? I see the discussion diverted a
little. I am curious on the answer for a program I am working on. Would
like to try and avoid the same mistake if there is one.
--

DaveG
Norway - Oslo - Skoyen
John wrote:
Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards

Jun 29 '06 #7

Dave Griffiths wrote:
Hi John

Did you find an answer to the problem? I see the discussion diverted a
little. I am curious on the answer for a program I am working on. Would
like to try and avoid the same mistake if there is one.
--

DaveG
Norway - Oslo - Skoyen
John wrote:
Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards


My opinion, having not done this for a long time:

1. be sure all the numbers used in the calculation are of type
currency; do not use any literals as VBA may decide to treat literals
as some type that we may not want them to be treated as.
So the calculation of the original poster whould be expanded to
something like:

Dim Tax as Currency
Dim Net as Currency
Dim TaxRate as Currency
Dim Per as Currency

Net = 12.35
TaxRate = 7
Per = 100

Then we must consider rounding. Many rounding methods use bankers
rounding. That is each number is rounded to its closest even
approximation eg. 1.315 is rounded to 1.32; this looks great until we
learn that 1.325 is ALSO rounded to 1.32. Many (most?) businesses and
tax collectors do not round in this way. They round all halves UP.

If bankers rounding is suitable for you, you can use the VBA round
function.

So

Tax = Round(New * TaxRate / Per, 2)

But if you want the general old rounding most of us learned in grade
school you will need another algorithm.
There are some at
http://www.xbeat.net/vbspeed/c_Round.htm
You could test these for speed and conformance with how you want 1.325
rounded.

If you chose one your calcuation would now look something like this:
Tax = Round02(New * TaxRate / Per, 2)

Another warning: In the olden days when we tried to store a five digit
decimal numeral like 7.23685 as a currency type the rounding to 7.2368
or 7.2369 was erratic. I have read that this has now been corrected but
.... I would try to avoid this kind of thing regardless.

Jun 29 '06 #8
On Fri, 23 Jun 2006 02:46:54 +0100, "John" <Jo**@nospam.infovis.co.uk>
wrote:
Hi

I am calculating tax as follows;

= [Net] * [TaxRate] / 100#

Client complains that there is sometimes difference in pennies in tax
calculation. Is there a better (more precise) way to calculate tax?

Thanks

Regards

Most states provide a table that shows the sales tax for amounts
between upper and lower amounts. I would recommend that you get this
chart and program it into your system. That would probably cure his
complaint.

Then, of course, you need to update the chart.

Bookreader
Jun 30 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: ejack | last post by:
Hello! I am having issues with my code. My program is supposed to take a given amount of money (1.33) and tell how many quarters, dimes, nickels and pennies would make up this sum of money. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.