Simple Forumula is returning 3.63797880709171E-12

Posted on 2006-06-01
Last Modified: 2006-11-18

I am trying to write a qry that does a simple minus calculation.  To explain I have created two other qry's that sum two tables. These two qry's are called

qryTotalPayments = sums each clients total payments $
qryTotalOrders = sums each clients total orders $

I have checked the values in both these qry's and they look correct.  The qryOutstandingAmount that I am having trouble with uses a join to linkboth qryTotalPayments & qryTotalOrders.  The join type only includes rows where the joined field is equal.

The basic formula is

AmountOutstanding = qryTotalOrders!total - qryTotalPayments

The problem is the qry returns the values that look correct, ie people who have paid exactly what they have ordered show a $value of $0.00. The problem is if I click the cell that contains the value $0.00 the figure changes to 3.63797880709171E-12.  Why on earth would this be happening? Thanks in advance for any pointers

Question by:robjeeves
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    what is the data type of the fields payments resp orders?
    LVL 58

    Accepted Solution

    Hello robjeeves

    This looks like a rounding error. Computers normally do not perform exact math. For example, you can type this in the immediate pane:

        ? 1-(30001/3-10000)*3

    And observe that the result is not 0, but 8.88178419700125E-16. This result reflects the fact that calculations are done with a certain number of digits (15 in this case), and that the remaining digits should be discarded.

    If both your sums are really just that: sums of currency values without any calculation, Jet should propagate and automatically round the result to 4 decimals. Obviously, this is not the case, so that you should round the result yourself:

        AmountOutstanding = Round( qryTotalOrders!total - qryTotalPayments, 2 )
        AmountOutstanding = CCur( qryTotalOrders!total - qryTotalPayments )

    It would probably be best to revise your queries (and perhaps even your data) to ensure they all have the currency type, or  convert any calculations to currency.

    Good luck!
    LVL 1

    Expert Comment

    AmountOutstanding = CCur(qryTotalOrders!total - qryTotalPayments)
    LVL 44

    Assisted Solution

    just so you understand that what you are getting is NOT an error, the value you are seeing


    is the same as 0.00000000000363797880709171

    which is very close to 0.00 , and the reason is undoubtedly round-off error, as explained by harfang.

    LVL 9

    Author Comment

    Thanks guys, I used the round formula suggested and it works a treat.  Most appreciated !!!

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now