0

Why is this not 0 in C#?

double _v1 = 1687.08;
double _v2 = 175.17;
double _v3 = 1511.91;
double _answer = (_v1 - _v2) - _v3;
Console.WriteLine($"{((_v1 - _v2) - _v3)}");
Console.WriteLine($"{_answer}");

look above, it's 0 when using a decimal

  • 2
    See also [Accuracy of floating point computations](https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems) – Alexey S. Larionov May 15 '23 at 12:40
  • 1
    Another [useful answer](https://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net) – StuartLC May 15 '23 at 12:42

0 Answers0