Double Data Type (Generating All Numbers between 2 numbers) (Specified Step)

  • Thread starter Thread starter Kevin993
  • Start date Start date
K

Kevin993

Guest
Greetings,

I wrote a simple function to list all existing numbers between 2 numbers (Double Data type because it might not be always an integer number) (with specified +step) and populate a listbox with the numbers generated:

Public Function Generate_Numbers(Start_NO As Double, End_NO As Double, sStep As Double,d_Listbox As ListBox)

Dim j As Double = Start_NO

Do While j < End_NO

d_Listbox.Items.Add(j)
j += sStep

Loop

d_Listbox.Items.Add(End_NO)



Return Nothing

End Function

As a simple test, I call the function this way :

Generate_Numbers(1,7,0.1,Listbox1)

Here is the results (Listbox1's items) :

1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
3
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
4
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
5
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
6
6.1
6.19999999999999
6.29999999999999
6.39999999999999
6.49999999999999
6.59999999999999
6.69999999999999
6.79999999999999
6.89999999999999
6.99999999999999
7

As you can see, from 6.1 to 7 there are many decimal digits generated. NO IDEA! What could be the reason ?

Continue reading...
 
Back
Top