Q: Matlab and C# floating point operations need to give same results I've converted some Matlab code to C#. The problem I have is that the result of the operations must be the same.
Matlab calculates 0.1 + 0.2 = 0.3, while C# = 0.30000000000000004 (https://0.30000000000000004.com/)
Calculation 1 - The same result in C# and Matlab :972,5635799999999
double test1 = 0.016209393 * 60000;
// 972,5635799999999

Calculation 2 - different in C# and Matlab: 
2397,1369799999998 in C# and 2397.13698 in Matlab
double test2 = 0.039952283 * 60000;
// 2397,1369799999998

If i use decimal in C# it is calculated to be the same as in Matlab, 2397.13698
decimal test3 = 0.039952283m * 60000;
// 2397.13698

The problem is that I can't use decimal for all calculations, as calculation 1 using decimal would return 972,56358 in C#, while it should be 972,5635799999999 as in Matlab.
How can I make sure I can get the same results from C# and Matlab? Would it be ok to find the base of the fractions and use double or decimal accordingly?
