A decimal
is just a number - it doesn't have a format.
You specify the format of a number when you display (or parse) it - if you're just looking at the value in the debugger, implicitly casting to string (e.g. setting the .Text
property of a control), or calling .ToString
without specifying a format, then you're implicitly using the default format of the system (including any cultural specifics). For decimal
that default format is G
(General), which shows the number in the most compact form possible. So if there is no fractional part to the decimal value, no decimal places are shown.
If you want to specify a particular format when you display the string, then use either string.Format
or .ToString
txtValue.Text = amount.ToString("N2");
or use any custom formatting you desire.
Note that some UI controls (perhaps including your TextBox.UIDecimal
) have a "Format" property to specify the format that is used when the value is displayed. In that case, you can set the format to N2
in the designer or in code-behind.