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?
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).
See more on this question at Stackoverflow