Minus Calculation problems

Minus Calculation problems

Post by Adrian Lingg » Wed, 18 Nov 1998 04:00:00



This is in reply to the rounding problem I had, but Ive now realised its not
a rounding error - its a minus error!

Heres what happens.

When I work out vat at 17.5% on a figure, say 39.00, it comes to 6.83
This is correct.  But now I need to minus the vat from my subtotal, say
1561.00.  The answer should be

                1561.00
                   6.83 -
                -------
                1554.17

But I get 1554.18 - 1 penny out every time.

But, when I add the VAT (I just did this as a test, it adds the VAT
perfectly (1561.00 + 6.83) = 1567.83

All my fields are calculated currency fields.

Does anyone know what I am doing wrong..

Would appreciate any help!

Thanks

Adrian Linggi

 
 
 

Minus Calculation problems

Post by Graha » Thu, 19 Nov 1998 04:00:00


How are you calculating the value (sorry I missed any early posts you made)?
Are you using floats?   What are you doing with the result of the
calculation to get your final numbers?  It sounds like your rounding error
is now just happening on the result of the subtraction, but it is still
rounding error.  TCurrencyFields are just glorified TFloatFields so they
work exactly like doubles when you do arithmetic with them.

39.0 * 0.175 isn't really 6.83 its 6.825.
1561.0 - 6.83 is 1554.17 but 1561.0 - 6.825 is 1554.175.
Depending on how you arrive at your final value it is entirely possible that
1554.175 becomes 1554.18 since TCurrentField just uses a call to FloatToStrF
to display the value so it is essentially going like this
FloatToStrF(1561.00 - (39.0 * 0.175), ffCurrency, 12,2);  ====> $1,554.18

Hope that helps.  Sorry again if I missed some stuff from earlier postings.

Respectfully yours,
graham


Quote:>This is in reply to the rounding problem I had, but Ive now realised its
not
>a rounding error - its a minus error!

>Heres what happens.

>When I work out vat at 17.5% on a figure, say 39.00, it comes to 6.83
>This is correct.  But now I need to minus the vat from my subtotal, say
>1561.00.  The answer should be

> 1561.00
>    6.83 -
> -------
> 1554.17

>But I get 1554.18 - 1 penny out every time.

>But, when I add the VAT (I just did this as a test, it adds the VAT
>perfectly (1561.00 + 6.83) = 1567.83

>All my fields are calculated currency fields.

>Does anyone know what I am doing wrong..

>Would appreciate any help!

>Thanks

>Adrian Linggi


 
 
 

1. Problem with date field

Hi,

I have the following statement:

SqlStg = "UPDATE dbo.tblProject"
SqlStg = SqlStg & " SET Pr_ExecMeeting# = " & Me.EC_Number & ", Pr_ExecDate
= " & Me.ECDate & " WHERE " & vCriteria

Me.ECDate refers to an unbound field on the form with a default value set to
Date().

When I execute the statement, the Pr_ExecDate always returns 12:00AM.
Am I missing something?

SF

2. We have another WINNER

3. Error 2757 - "There is a problem accessing the property or method of the OLE object"

4. How to return a column as Y/N ?

5. OpenStoredProcedure problem in macros and modules - Access 2000

6. Which version of 8

7. Autonumber problem when Xfer from SQL7 db to Access XP

8. combo box not populating rest of form (resync problem?)

9. SQL Server Tables Linked in Access Problem

10. Newbie: Help on calculation needed.

11. Problems access Users collection when connected to MSDE

12. Upsizing Problem in Access 2000