Re: VBA Code - Dividing Numbers
From: Kevin K. Sullivan (reply_at_the.news.group)
Date: 10/25/04
- Next message: Tim Ferguson: "Re: VBA Code - Dividing Numbers"
- Previous message: Tim Ferguson: "Re: Reposted - How to create a connection for SQL database"
- In reply to: Access101: "VBA Code - Dividing Numbers"
- Next in thread: Tim Ferguson: "Re: VBA Code - Dividing Numbers"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 25 Oct 2004 17:39:19 -0400
Go to the immediate pane and type
? 75/999
you'll see the result:
7.50750750750751E-02
Note the last four characters -- E-02. Access is using scientific notation
to denote
7.507507... * 10 ^ -2
7.507507 * 0.01
0.07507507...
It's doing the math correctly, but you have an implicit conversion from
double to string that isn't cooperating with you.
Try:
' old code
'Print #1, dblVal & Chr(9) & x
'new code, uses comma to separate outputs with tab character
Print #1, dblVal, x
Another way is to use Format to make an explicit conversion from number to
string:
Print #1, Format(dblVal, "0.000000"), Format(x, "0")
This way will avoid scientific notation in all cases.
HTH,
Kevin
"Access101" <Access101@discussions.microsoft.com> wrote in message
news:FCBB8F66-F3FF-45F4-A0A1-00A452DC6B30@microsoft.com...
>
> I divide the number 75 by several numbers, however many of the resulting
> numbers have a misplaced decimal point. That is, 75 / 999 = 7.507
> (Incorrect) . But 75 / 1000 = .075 (Correct). And then 75/ 1001 = 7.492
>
> Here is the code. Any help is appreciated:
>
> Dim dblVal As Double, x as integer
> Open "C:\tmp.txt" For Output As #1
> For x = 999 To 2000
> dblVal = 75 / x
> Print #1, dblVal & Chr(9) & x
> Next x
> Close #1
>
- Next message: Tim Ferguson: "Re: VBA Code - Dividing Numbers"
- Previous message: Tim Ferguson: "Re: Reposted - How to create a connection for SQL database"
- In reply to: Access101: "VBA Code - Dividing Numbers"
- Next in thread: Tim Ferguson: "Re: VBA Code - Dividing Numbers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|