Problems with ... Convert ?
I am getting a very strange error.
I have a C# application that has this code :
double a = 0;
double b = 0;
double c = 0;
In the code, the values for "a", "b" and "c" changes and gets these values:
a = 1716
b = Convert.ToDouble(and gets a value from the database, in this case the value in the field is 0) so b will look like this :
b = Convert.ToDouble(0)
and c is like b but the value in the database field is 1716 so:
b = Convert.ToDouble(1716)
Now we have this situation :
a = 1716
b = 0
c = 1716
Later in the code there's a formula like this :
a -= (b + c)
Theorically I would get a value of 0 (zero) for "a" because :
a = 1716 - (0 + 1716)
a = 0
The problem is that I'm not getting 0 but a very strange value like this :
that is equal to : 0,00000000556453 (or somethink like that)
And in the code if value of "a" is different from 0 it does not allow you to continue with other options, but I need to continue with those options because for me, "a" is equal to 0.
The questions are :
how is it possible that 1716 - (0 + 1716) is not equal to 0 but equal to -2,273456E-13 ?!?!?!?!?!?!?
What's going on ?, what's wrong ?, how can I solve this problem ? is it a problem related to the Convert.ToDouble ?
At this point I can't check if the value of "a" is <= 0 to set the value for "a" to 0 because "a" can contain negative values, so I don't know how to solve this problem.
Any Ideas ?
Thank you all
The binary representation is not the same as an integer, when the convert to double happens and then is used in the calculation it gives a double which is reasonable, but in your calculation as an example you expectthe result to be a integer on your check you will have to compare by converting it back to an integer.. Or compare the value with a double
I have come across a small marginal difference when converting integers to double
By Force Flow in forum Java
Last Post: 06-29-2006, 02:01 PM
By Sandra in forum VB Classic
Last Post: 07-19-2002, 02:41 AM
By Anthony Meo in forum Enterprise
Last Post: 01-15-2002, 05:44 PM
By Ted Young in forum Database
Last Post: 08-07-2001, 04:53 PM
By Sarel j Smit in forum Database
Last Post: 05-24-2001, 11:35 PM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center