Funny Behaviour

By Roy Osherove In .Net Original

Markdown version

Historical article · Originally published June 16, 2003; technical details may be outdated.

Tamar, a friend of mine, alerted me to this funny behaviour.

can anyone tell me why the following code:

static void Main(string[] args)

{

Console.WriteLine(21 - 5.45);

Console.WriteLine(21 - 20.45);

Console.Read();

}

produces this:

15.55
0.550000000000001

This happens in C#,VB.NET and VB6.  What's going on here?

More in .Net Original

All posts in .Net Original