by Michael S. Kaplan, published on 2008/04/28 15:11 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2008/04/28/8435937.aspx
The weirdness is easily noted if you try the following code in both .NET <= 1.1 and .NET >= 2.0:
static void Main(string[] args) {
Decimal val1 = 0m;
Decimal val2 = 0.0m;
Decimal val3 = 0.00m;
Decimal val4 = 1m;
Decimal val5 = 1.0m;
Decimal val6 = 1.00m;
Console.WriteLine("0 → " + val1.ToString());
Console.WriteLine("0.0 → " + val2.ToString());
Console.WriteLine("0.00 → " + val3.ToString());
Console.WriteLine("1 → " + val4.ToString());
Console.WriteLine("1.0 → " + val5.ToString());
Console.WriteLine("1.00 → " + val6.ToString());
}
The output in the console would be as follows in <= 1.1:
0 → 0
0.0 → 0
0.00 → 0
1 → 1
1.0 → 1.0
1.00 → 1.00
==
and then as follows in >= 2.0:
0 → 0
0.0 → 0.0
0.00 → 0.00
1 → 1
1.0 → 1.0
1.00 → 1.00
Subtle difference, that -- but one that does seem more consistent -- and was an intentional "break" to compatibility for the sake of that consistency that only affects the "0" values.
Note that this has no connection to Insanity defined: In the real world -0 == 0, in Vista -0 < 0, and in Windows Server 2008 -0 ≮ 0 at all, or any of the collation mistakes there.
And it isn't connected with Decimal Negative Zero Representation from over on the BCLTeam blog, either.
Because we aren't dealing with -0 versus 0, we are dealing with 0 vs. 0.0 and so on. :-)
Though in a way we are talking about the same thing --- given that the goal of .NET here is to capture minute distinctions that keep exactly the same value no matter what -- since to most people in the universe
0 == 0.0 == 0.00 == -0 == -0.0 == -0.00
and so on.
And we won't even talk about the StrCmpLogicalW changes that differentiate between other things that are kind of the same, making
000001 < 00001 < 0001 < 001 < 01 < 1
This last part does seem a little inconsistent, huh? :-)
It may seem a little silly in the end to spend a lot of time keeping track of and sometimes even changing results of these edge cases.
Much Ado About Nothing, if you ask me. :-)
This blog brought to you by 0 (U+0030, aka DIGIT ZERO)