I need to do some work with variables of the type double and in the calculations I've come across something I do not understand. I know floating point types are not exact but it has enough precision for what I need.
First I multiply a value of 200 with a multiplier of 1.1 and get 220.00000000000003 which is expected and close enough to 220 and then I subtract that from the expected value (220). The result should be 0 or very close to 0. Instead I get -2.8421709430404007E-14 which I cannot explain.
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
double u = 200;
double v = 1.1;
double x = u * v;
double y = 220;
double z = y - x;
Console.WriteLine(u + " * " + v + " = " + x);
Console.WriteLine(y + " - " + x + " = " + z);
Console.ReadLine();
}
}
}
Any ideas?