ToString method of decimal type

Theoretically the decimal type has nothing special. This is a number value from the range ±1.0 × 10−28 to ±7.9 × 1028. The one thing which can makes problems is ToString method. This may return different values ​​depending on the .NET version.

     decimal d = 15.000m;
     d.ToString();
    

Returns "15" in .net 1.0 and "15.000" in other versions. This is not big issue but not the last one. Quite often we retrieves the values ​​from the database. In this case ToString method can also return different value than other decimal variables in our code. It depends on the decalration of specific column/variable in database. e.g

    decimal(18,2) /*in c# code returns "15.00"*/
    decimal(18,4) /*in c# code returns "15.0000"*/
    

Technically this is not a big problem, but can cause the following problem.

     decimal d1 = (decimal)15;
     decimal d2 = (decimal)reader["decColumn"];  //It returns 15 but it is declared as decimal(18,4) in SQL 
     if (d1 == d2) 
        MessageBox.Show("d1 equals d2");
     else
        MessageBox.Show("d1 not equals d2");
     if (d1.ToString() == d2.ToString()) 
        MessageBox.Show("d1 ToString equals d2 ToString");
     else
        MessageBox.Show("d1 ToString not equals d2 ToString");
    

Above code returns "d1 equals d2" and "d1 ToString not equals d2 ToString" which is a little confusing.