NeuralJack Posted February 22, 2007 Posted February 22, 2007 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 Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
mskeel Posted February 22, 2007 Posted February 22, 2007 That's just the nature of the beast with floats. There are limitations to the accuracy when representing floats. Try using Decimal types instead. Quote
NeuralJack Posted February 22, 2007 Author Posted February 22, 2007 bah, ok thanks for the info Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.