vb calculation is diffrent than C# calculation [modified]
-
Hi, I have a vb application, which contains lots of calculation and I am converting that application to asp.net C#. There are so many variables of double types in the vb application and I also took double in the c# for those variables. Now problem is that I do calculation with the same equation in both the application, however result value does not match. I have a variable var1 in vb the calculate double value is 1.63870925710649 (for vb) and 1.6387092571064941 (for c#), I do not understand why these values are different for the same datatype. And I have to use this variable in my equation, since both language has different value, this may be the reason of different final output. Some times I have to break the same equation into two or more equations for the C# , to get the same result in C# and sometimes I get the same result. But sometimes I get the value in c# which does not match the value of vb. I do not understand which calculation is right vb or C#.
Pankaj
modified on Tuesday, December 8, 2009 2:16 AM
-
Hi, I have a vb application, which contains lots of calculation and I am converting that application to asp.net C#. There are so many variables of double types in the vb application and I also took double in the c# for those variables. Now problem is that I do calculation with the same equation in both the application, however result value does not match. I have a variable var1 in vb the calculate double value is 1.63870925710649 (for vb) and 1.6387092571064941 (for c#), I do not understand why these values are different for the same datatype. And I have to use this variable in my equation, since both language has different value, this may be the reason of different final output. Some times I have to break the same equation into two or more equations for the C# , to get the same result in C# and sometimes I get the same result. But sometimes I get the value in c# which does not match the value of vb. I do not understand which calculation is right vb or C#.
Pankaj
modified on Tuesday, December 8, 2009 2:16 AM
Both calculations are correct, except that the precision in C# is more than precision in VB 1.63870925710649 [VB] 1.6387092571064941 [C#] Just round off the value the number of digits required and use it!
-
Both calculations are correct, except that the precision in C# is more than precision in VB 1.63870925710649 [VB] 1.6387092571064941 [C#] Just round off the value the number of digits required and use it!
Thanks for your replay. But this is not the problem. How do I know how much digit I have to round up. There are more than 100 double variables and more than 100 complex calculation, then its very difficult to round each and every variable or calculated value, however in vb they did not use any round method.
Pankaj
-
Thanks for your replay. But this is not the problem. How do I know how much digit I have to round up. There are more than 100 double variables and more than 100 complex calculation, then its very difficult to round each and every variable or calculated value, however in vb they did not use any round method.
Pankaj
I understand that it can really be a pain in your scenario. How about doing the rounding off at specific check points? BTW, what is the system precision that is expected??
-
Hi, I have a vb application, which contains lots of calculation and I am converting that application to asp.net C#. There are so many variables of double types in the vb application and I also took double in the c# for those variables. Now problem is that I do calculation with the same equation in both the application, however result value does not match. I have a variable var1 in vb the calculate double value is 1.63870925710649 (for vb) and 1.6387092571064941 (for c#), I do not understand why these values are different for the same datatype. And I have to use this variable in my equation, since both language has different value, this may be the reason of different final output. Some times I have to break the same equation into two or more equations for the C# , to get the same result in C# and sometimes I get the same result. But sometimes I get the value in c# which does not match the value of vb. I do not understand which calculation is right vb or C#.
Pankaj
modified on Tuesday, December 8, 2009 2:16 AM
Can you provide an example of a calculation which doesn't give the same results? There are some subtle differences in math between C# and VB which could explain it.
David Anton Convert between VB, C#, C++, & Java http://www.tangiblesoftwaresolutions.com