T
Tschuß
Hi all,
I was making an exercise for my students when I have discovered a bug
when I use the function Round.
In the column E, you have this data
Last quote
32,13
31,46
31,67
31,17
30,12
31,86
31,96
33,28
33,35
33,38
33,08
33,34
32,38
31,98
32,09
32,73
33,05
32,82
33,08
My program is very simple. I calculate the average of the first 20
cells and I write the result in Cells(21,6)
Why the round function doesn't work in the first Sub (the result is
32,4099998474121) and works in the second one ?
Thanks for any idea.
Sub Step_1()
Dim Temp_Sum As Single
Dim index_loop As Integer
For index_loop = 1 To 20
Temp_Sum = Temp_Sum + Cells(1 + index_loop, 5)
Next
Cells(21, 6) = Round(Temp_Sum / 20, 2)
End Sub
(the cell(1,6) has the value 20)
Sub Step_2()
Dim Temp_Sum As Single
Dim index_loop As Integer
For index_loop = 1 To Cells(1, 6)
Temp_Sum = Temp_Sum + Cells(1 + index_loop, 5)
Next
Cells(1 + Cells(1, 6), 6) = Round(Temp_Sum / Cells(1, 6), 2)
End Sub
I was making an exercise for my students when I have discovered a bug
when I use the function Round.
In the column E, you have this data
Last quote
32,13
31,46
31,67
31,17
30,12
31,86
31,96
33,28
33,35
33,38
33,08
33,34
32,38
31,98
32,09
32,73
33,05
32,82
33,08
My program is very simple. I calculate the average of the first 20
cells and I write the result in Cells(21,6)
Why the round function doesn't work in the first Sub (the result is
32,4099998474121) and works in the second one ?
Thanks for any idea.
Sub Step_1()
Dim Temp_Sum As Single
Dim index_loop As Integer
For index_loop = 1 To 20
Temp_Sum = Temp_Sum + Cells(1 + index_loop, 5)
Next
Cells(21, 6) = Round(Temp_Sum / 20, 2)
End Sub
(the cell(1,6) has the value 20)
Sub Step_2()
Dim Temp_Sum As Single
Dim index_loop As Integer
For index_loop = 1 To Cells(1, 6)
Temp_Sum = Temp_Sum + Cells(1 + index_loop, 5)
Next
Cells(1 + Cells(1, 6), 6) = Round(Temp_Sum / Cells(1, 6), 2)
End Sub