Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Significant Figures and Resolution

Status
Not open for further replies.

blboyd

Programmer
Jun 6, 2003
1
0
0
US
Upon exploring a problem with our software we ran into an anomly that none of us understand.

Using this code - all I am doing is adding .001 to .001 an so on. Looks that simple right?? If you run the code it will start generating numbers like: 6.000001E-03

Can anyone explain this or have a fix for this??

Thanks,
Brandon


Code:
Sub Main()
Dim TestArray(1000) As Single
Dim i As Integer

TestArray(0) = 0.001

    For i = 1 To 999
        TestArray(i) = TestArray(i - 1) + 0.001
    Next i
    
End Sub
 

try currency...
[tt]
Dim TestArray(1000) As Currency
Dim i As Integer

TestArray(0) = 0.001

For i = 1 To 999
TestArray(i) = TestArray(i - 1) + 0.001
Next i

[/tt]

Good Luck

 
Hi there

The code is fine. I've tested it also and it works properly. How are you testing the resulting values ? Are you formatting the value in a certain way to view it ?

If you add the following line in the For Loop you will see the results are correct.

Debug.Print TestArray(i)
 
read hookbob's post. It is a bit pithy -but absoloutly accurate.

or (with SLIGHTLY more context)

Code:
? 6 * 0.001
 0.006 
? 6e-3
 0.006

e.g. 0.006 = 6e-3


Now -if you want / need / desire a SPECIFIC format for this trivia, you should avail yourself of the ever present {F1} and snoop through the ubiquitious "Format" function.




MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top