Tuesday, October 6, 2009

Decimal formatting in .Net

One day I was having problems with decimal numbers showing up as strings with lots of zeros after the decimal point. Since they were whole numbers, I had naively expected that they would always be displayed without any zeros, at least with the format string I was using.

Alas, the documentation disagreed with me.

Apparently the precision of the decimal will show up when calling ToString in the manner in which I was calling it. So my unit tests all passed because I was constructing a decimal 42, rather than a decimal 42.00000.

Microsoft 1, me 0.

No comments:

Post a Comment