EDN Admin
Well-known member
So i have a simple little thing i am toying around with, well apparently its not so simple?
So look at the example output below, why does it do that?(I dont get any problems when I use a Decimal datatype instead of Double)
Heres the code:
<pre class="prettyprint lang-vb" style=" Option Strict On
Public Class Form1
Private Property _Angle As Double
Public Property Angle As Double
Get
Return _Angle
End Get
Set(value As Double)
_Angle = ResolveRotationAngle(value)
End Set
End Property
Function ResolveRotationAngle(value As Double) As Double
If value > 360 Then value = value - 360
If value < -360 Then value = value + 360
If value = 360 Then value = 0
If value = -360 Then value = 0
Return value
End Function
Sub d(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseWheel
Dim MathFactor As Double = 0.1
Select Case e.Delta
Case Is > 0
Dim OldAngle As Double = Angle
Angle = Angle + MathFactor
TextBox1.Text = TextBox1.Text & OldAngle.ToString & " + " & MathFactor.ToString & " = " & Angle & vbCrLf
Case Is < 0
Dim OldAngle As Double = Angle
Angle = Angle - MathFactor
TextBox1.Text = TextBox1.Text & OldAngle.ToString & " + " & MathFactor.ToString & " = " & Angle & vbCrLf
End Select
End Sub
End Class[/code]
<br/>
Here is the example output:
0 + 0.1 = 0.1<br/>
0.1 + 0.1 = 0.2<br/>
0.2 + 0.1 = 0.3<br/>
0.3 + 0.1 = 0.4<br/>
0.4 + 0.1 = 0.5<br/>
0.5 + 0.1 = 0.6<br/>
0.6 + 0.1 = 0.7<br/>
0.7 + 0.1 = 0.8<br/>
0.8 + 0.1 = 0.9<br/>
0.9 + 0.1 = 1<br/>
1 + 0.1 = 1.1<br/>
1.1 + 0.1 = 1.2<br/>
1.2 + 0.1 = 1.3<br/>
1.3 + 0.1 = 1.4<br/>
1.4 + 0.1 = 1.5<br/>
1.5 + 0.1 = 1.6<br/>
1.6 + 0.1 = 1.7<br/>
1.7 + 0.1 = 1.8<br/>
1.8 + 0.1 = 1.9<br/>
1.9 + 0.1 = 2<br/>
2 + 0.1 = 2.1<br/>
2.1 + 0.1 = 2.2<br/>
2.2 + 0.1 = 2.3<br/>
2.3 + 0.1 = 2.4<br/>
2.4 + 0.1 = 2.5<br/>
2.5 + 0.1 = 2.6<br/>
2.6 + 0.1 = 2.7<br/>
2.7 + 0.1 = 2.8<br/>
2.8 + 0.1 = 2.9<br/>
2.9 + 0.1 = 3<br/>
3 + 0.1 = 3.1<br/>
3.1 + 0.1 = 3.2<br/>
3.2 + 0.1 = 3.3<br/>
3.3 + 0.1 = 3.4<br/>
3.4 + 0.1 = 3.5<br/>
3.5 + 0.1 = 3.6<br/>
3.6 + 0.1 = 3.7<br/>
3.7 + 0.1 = 3.8<br/>
3.8 + 0.1 = 3.9<br/>
3.9 + 0.1 = 4<br/>
4 + 0.1 = 4.1<br/>
4.1 + 0.1 = 4.2<br/>
4.2 + 0.1 = 4.3<br/>
4.3 + 0.1 = 4.4<br/>
4.4 + 0.1 = 4.5<br/>
4.5 + 0.1 = 4.6<br/>
4.6 + 0.1 = 4.7<br/>
4.7 + 0.1 = 4.8<br/>
4.8 + 0.1 = 4.9<br/>
4.9 + 0.1 = 5<br/>
5 + 0.1 = 5.1<br/>
5.1 + 0.1 = 5.2<br/>
5.2 + 0.1 = 5.3<br/>
5.3 + 0.1 = 5.4<br/>
5.4 + 0.1 = 5.5<br/>
5.5 + 0.1 = 5.6<br/>
5.6 + 0.1 = 5.7<br/>
5.7 + 0.1 = 5.8<br/>
5.8 + 0.1 = 5.9<br/>
5.9 + 0.1 = 5.99999999999999<br/>
5.99999999999999 + 0.1 = 6.09999999999999<br/>
6.09999999999999 + 0.1 = 6.19999999999999<br/>
6.19999999999999 + 0.1 = 6.29999999999999<br/>
6.29999999999999 + 0.1 = 6.39999999999999<br/>
6.39999999999999 + 0.1 = 6.49999999999999<br/>
6.49999999999999 + 0.1 = 6.59999999999999<br/>
6.59999999999999 + 0.1 = 6.69999999999999<br/>
6.69999999999999 + 0.1 = 6.79999999999999<br/>
6.79999999999999 + 0.1 = 6.89999999999999<br/>
6.89999999999999 + 0.1 = 6.99999999999999<br/>
<
If you want something youve never had, you need to do something youve never done.
<br/>
Everyone(not just the thread starter) should take the time to mark helpful posts, propose answers, and mark answers to questions.
<br/>
View the full article
So look at the example output below, why does it do that?(I dont get any problems when I use a Decimal datatype instead of Double)
Heres the code:
<pre class="prettyprint lang-vb" style=" Option Strict On
Public Class Form1
Private Property _Angle As Double
Public Property Angle As Double
Get
Return _Angle
End Get
Set(value As Double)
_Angle = ResolveRotationAngle(value)
End Set
End Property
Function ResolveRotationAngle(value As Double) As Double
If value > 360 Then value = value - 360
If value < -360 Then value = value + 360
If value = 360 Then value = 0
If value = -360 Then value = 0
Return value
End Function
Sub d(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseWheel
Dim MathFactor As Double = 0.1
Select Case e.Delta
Case Is > 0
Dim OldAngle As Double = Angle
Angle = Angle + MathFactor
TextBox1.Text = TextBox1.Text & OldAngle.ToString & " + " & MathFactor.ToString & " = " & Angle & vbCrLf
Case Is < 0
Dim OldAngle As Double = Angle
Angle = Angle - MathFactor
TextBox1.Text = TextBox1.Text & OldAngle.ToString & " + " & MathFactor.ToString & " = " & Angle & vbCrLf
End Select
End Sub
End Class[/code]
<br/>
Here is the example output:
0 + 0.1 = 0.1<br/>
0.1 + 0.1 = 0.2<br/>
0.2 + 0.1 = 0.3<br/>
0.3 + 0.1 = 0.4<br/>
0.4 + 0.1 = 0.5<br/>
0.5 + 0.1 = 0.6<br/>
0.6 + 0.1 = 0.7<br/>
0.7 + 0.1 = 0.8<br/>
0.8 + 0.1 = 0.9<br/>
0.9 + 0.1 = 1<br/>
1 + 0.1 = 1.1<br/>
1.1 + 0.1 = 1.2<br/>
1.2 + 0.1 = 1.3<br/>
1.3 + 0.1 = 1.4<br/>
1.4 + 0.1 = 1.5<br/>
1.5 + 0.1 = 1.6<br/>
1.6 + 0.1 = 1.7<br/>
1.7 + 0.1 = 1.8<br/>
1.8 + 0.1 = 1.9<br/>
1.9 + 0.1 = 2<br/>
2 + 0.1 = 2.1<br/>
2.1 + 0.1 = 2.2<br/>
2.2 + 0.1 = 2.3<br/>
2.3 + 0.1 = 2.4<br/>
2.4 + 0.1 = 2.5<br/>
2.5 + 0.1 = 2.6<br/>
2.6 + 0.1 = 2.7<br/>
2.7 + 0.1 = 2.8<br/>
2.8 + 0.1 = 2.9<br/>
2.9 + 0.1 = 3<br/>
3 + 0.1 = 3.1<br/>
3.1 + 0.1 = 3.2<br/>
3.2 + 0.1 = 3.3<br/>
3.3 + 0.1 = 3.4<br/>
3.4 + 0.1 = 3.5<br/>
3.5 + 0.1 = 3.6<br/>
3.6 + 0.1 = 3.7<br/>
3.7 + 0.1 = 3.8<br/>
3.8 + 0.1 = 3.9<br/>
3.9 + 0.1 = 4<br/>
4 + 0.1 = 4.1<br/>
4.1 + 0.1 = 4.2<br/>
4.2 + 0.1 = 4.3<br/>
4.3 + 0.1 = 4.4<br/>
4.4 + 0.1 = 4.5<br/>
4.5 + 0.1 = 4.6<br/>
4.6 + 0.1 = 4.7<br/>
4.7 + 0.1 = 4.8<br/>
4.8 + 0.1 = 4.9<br/>
4.9 + 0.1 = 5<br/>
5 + 0.1 = 5.1<br/>
5.1 + 0.1 = 5.2<br/>
5.2 + 0.1 = 5.3<br/>
5.3 + 0.1 = 5.4<br/>
5.4 + 0.1 = 5.5<br/>
5.5 + 0.1 = 5.6<br/>
5.6 + 0.1 = 5.7<br/>
5.7 + 0.1 = 5.8<br/>
5.8 + 0.1 = 5.9<br/>
5.9 + 0.1 = 5.99999999999999<br/>
5.99999999999999 + 0.1 = 6.09999999999999<br/>
6.09999999999999 + 0.1 = 6.19999999999999<br/>
6.19999999999999 + 0.1 = 6.29999999999999<br/>
6.29999999999999 + 0.1 = 6.39999999999999<br/>
6.39999999999999 + 0.1 = 6.49999999999999<br/>
6.49999999999999 + 0.1 = 6.59999999999999<br/>
6.59999999999999 + 0.1 = 6.69999999999999<br/>
6.69999999999999 + 0.1 = 6.79999999999999<br/>
6.79999999999999 + 0.1 = 6.89999999999999<br/>
6.89999999999999 + 0.1 = 6.99999999999999<br/>
<
If you want something youve never had, you need to do something youve never done.
<br/>
Everyone(not just the thread starter) should take the time to mark helpful posts, propose answers, and mark answers to questions.
<br/>
View the full article