Article View: comp.databases.ms-access
Article #333Rounding problems with Access
From: Larry LeBlanc
Date: Thu, 15 Jul 1999 00:00
Date: Thu, 15 Jul 1999 00:00
80 lines
3404 bytes
3404 bytes
Good day,
Can anyone explain to me why the following source code:
===================================
Private Sub Command9_Click()
Dim Looper As Single
For Looper = 0 To 1 Step 0.1
Debug.Print Looper
Stop
Next Looper
End Sub
===================================
leads to the following results:
===================================
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8000001
0.9000001
===================================
Why is Access having difficulties with such a basic program. I am writing a
complex financial simulations (on the Canadian Mutual Fund Market), and what
I consider basic math is being completely mangled by Access. For example,
when I run the following simplified code:
===================================
Dim SharesToPurchase As Long
Dim Bank As Currency
Dim ClosingPrice As Single
SharesToPurchase = Int(Bank / ClosingPrice)
Debug.Print "Bank Balance Before Transaction = " & Str(Bank)
Debug.Print "Closing Price = " & Str(ClosingPrice)
Debug.Print "Shares To Purchase = " & Str(SharesToPurchase)
Debug.Print "Transaction Amount = " & Str(SharesToPurchase *
ClosingPrice)
Bank = Bank - (SharesToPurchase * ClosingPrice)
Debug.Print "Bank Balance After Transaction = " & Str(Bank)
Stop
===================================
I get the following results:
===================================
Bank Balance Before Transaction = 1000000
Closing Price = 15.06
Shares To Purchase = 66401
Transaction Amount = 999999.087862968
Bank Balance After Transaction = .912137031555176
===================================
Does anyone know of a Microsoft KnowledgeBase article that can help me with
this problem? In addition to posting a follow-up to this problem, can you
please e-mail me directly (mailto:larry.leblanc@sympatico.ca) as I cannot
follow this newsgroup.
TIA,
Larry
--
===================================================================
Larry LeBlanc, CNE-3
Montreal, Quebec, CANADA
mailto:larry.leblanc@sympatico.ca (flames directed to /dev/null)
-------------------------------------------------------------------
This message was compiled and sent using environmentally friendly
recycled electrons and was not tested on animals.
===================================================================
Technical Details
Message-ID:
<wQkj3.4$PZ3.247@198.235.216.4>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111a5a,73518ce6c7069b00,start X-Google-Attributes: gid111a5a,public X-Google-Thread: 1131f0,73518ce6c7069b00,start X-Google-Attributes: gid1131f0,public X-Google-Thread: ff0ac,73518ce6c7069b00,start X-Google-Attributes: gidff0ac,public X-Google-Thread: 102b1d,73518ce6c7069b00,start X-Google-Attributes: gid102b1d,public From: "Larry LeBlanc" <larry.leblanc@sympatico.ca> Subject: Rounding problems with Access Date: 1999/07/15 Message-ID: <wQkj3.4$PZ3.247@198.235.216.4> X-Deja-AN: 501310245 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 X-Trace: 198.235.216.4 932043164 207.61.185.2 (Thu, 15 Jul 1999 08:52:44 EDT) Organization: Bell Solutions NNTP-Posting-Date: Thu, 15 Jul 1999 08:52:44 EDT Newsgroups: comp.databases.ms-access,de.comp.datenbanken.ms-access,es.comp.bd.ms-access,microsoft.public.access.modulesdaovba