Heaven
Newcomer
I'm using visual studio.net pro, and this is occuring when I'm using VB
Hope some one has the answer to this one.
I just want to know the Why this happens.
Here's my code:
Dim l as Long
Dim S as Single
l = Long.MaxValue 'set the long variable to its maximum value
Debug.WriteLine(l) 'display the results to output (which are 922337203684775807)
s= Convert.ToString(l) 'convert the long to a string
s -=1000000000000 'subtract 1 trillion form the value
l= Convert.toInt64(s) 'convert the answer back to a long
Debug.WriteLine(l) 'display the results to ourput (which are 9223370937343148032)
'end of code
now as you can see you don't get what you would expect. a single should have just rounded off at 7 places and returned the answer of 9223371 + a lot of trailing zeros.
I've looked at the .net library and the only thing I can find is that the results would be "inaccurate" duh.... I am trying to find out why . any ideas??? i'm sure it has something to do with overflow and possibly PositiveInfinity.
Hope some one has the answer to this one.
I just want to know the Why this happens.
Here's my code:
Dim l as Long
Dim S as Single
l = Long.MaxValue 'set the long variable to its maximum value
Debug.WriteLine(l) 'display the results to output (which are 922337203684775807)
s= Convert.ToString(l) 'convert the long to a string
s -=1000000000000 'subtract 1 trillion form the value
l= Convert.toInt64(s) 'convert the answer back to a long
Debug.WriteLine(l) 'display the results to ourput (which are 9223370937343148032)
'end of code
now as you can see you don't get what you would expect. a single should have just rounded off at 7 places and returned the answer of 9223371 + a lot of trailing zeros.
I've looked at the .net library and the only thing I can find is that the results would be "inaccurate" duh.... I am trying to find out why . any ideas??? i'm sure it has something to do with overflow and possibly PositiveInfinity.