I have the following field in a query:
Where [Quantity] is a decimal, such as 100 or 100.23 etc. and [StockMultiplier] is either -1 or +1.
In the source tables, both fields are defined as type double.
The Sum query works fine, unless the sum should be equal to zero. In these cases, I get some very obscure rounding errors. For example, given the following data:
I get the following result in the query: -1.4210854715202 E-14 (rather than 0)
Can anyone help with this?
I tried writing a function to "force" the result I wanted. If I express the return value as Currency I see the query result as required (but if it is double the problem persists). This seems far from ideal though.
Code:
Quantity: Sum([qrytransactions].[Quantity]*[StockMultiplier])
In the source tables, both fields are defined as type double.
The Sum query works fine, unless the sum should be equal to zero. In these cases, I get some very obscure rounding errors. For example, given the following data:
Code:
Quantity, StockMultiplier 100, 1 0.118, 1 0.112, 1 100.23, -1
Can anyone help with this?
I tried writing a function to "force" the result I wanted. If I express the return value as Currency I see the query result as required (but if it is double the problem persists). This seems far from ideal though.
Code:
Expr1: Sum(CalculateQuantity([qrytransactions].[Quantity],[StockMultiplier]))
Code:
Public Function CalculateQuantity(qty As Double, multiple As Double) As Currency
If multiple = -1 Then
CalculateQuantity = -qty
Else
CalculateQuantity = qty
End If
End Function
Comment