Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This is an odd problem, and I'm not sure how it's arising. But Given this code the floating point addition gets messed up by 0.000000000000001 every so often. Is there a way to stop it?

 

 Dim Single1 As Single = 0
 Dim AddAmount As Single = 0.001

 For i As Integer = 0 To 2000
     Single1 = Single1 + AddAmount
     Debug.WriteLine(Single1.ToString)
 Next

 

 

In the Debug Window This happens now and then:

0.025
0.026
0.027
0.028
0.029
0.03
0.031
0.032
0.033
0.034
0.035
0.03599999
0.03699999
0.03799999

or 

1.047
1.048
1.049
1.05
1.051
1.05199999999999
1.05299999999999
1.05399999999999

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...