Is there a string format that can be used on a decimal so that the following results are obtained?
123 => "123"
123.4 => "123.40"
123.45 => "123.45"
123.456 => "123.46"
In English, the number should always be displayed with exactly two decimals, except when it holds an integer value, when it should have no decimals (so no “123.00” displays are allowed).
I don’t know of any such format, I’m afraid. You might need to use:
EDIT: The code above will only work when
dis in the range betweenint.MinValueandint.MaxValue. Obviously you can do better than that usinglong, but if you want to cover the full range ofdecimalyou’ll need something a little more powerful.