Hi @Samoj Bhattarai , Welcome to Microsoft Q&A.
This is due to a problem with double precision data.
Floating point numbers have limited precision and may introduce small rounding errors into calculations.
In this case the sum of the numbers should be 0, but due to rounding errors you will get a very small non-zero value.
Typically, we do some processing on the result.
For example, as below, round the data to 2 decimal places and format it as "0.00".
double sum = numbers.Sum(x => x);
double roundedSum = Math.Round(sum, 2); // Round the sum to 2 decimal places
string numberSum = roundedSum.ToString("0.00"); // Format the sum with two decimal places
Console.WriteLine("SUM : " + numberSum);
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.