Why does decimal min value not convert to a string?

The following console app crashes:

decimal dec = decimal.MinValue;
string str = string.Format("{0:d}", dec);

Console.WriteLine(str);

The error is:

Format specifier was invalid.

Given that I'm essentially formatting a decimal as a decimal, what is wrong with this?

Jon Skeet
people
quotationmark

From the documentation:

This format is supported only for integral types.

decimal isn't an integral type.

The fact that the format type is called "decimal" is unfortunate, basically. It's because it formats integers in base 10, but it's not directly related to the decimal type.

I suspect you want F, G or N (or possibly something else, based on your actual requirements, which aren't really clear).

people

See more on this question at Stackoverflow