title: Formatting Decimal Values from SQL Server Database
body: <p>I'm working with an existing SQL Server database, with a table column defined as <code>decimal(4,2)</code>. However, I've been asked to prevent the code from rounding decimal places.</p>
  
  <p>So I tried changing the column type to <code>decimal</code>, which is automatically converted to <code>decimal(18, 0)</code>, which promptly wiped out any fractional portion of my existing values. (Nice. The default decimal type is an integer. What's the point?)</p>
  
  <p>So I tried changing the column type to <code>decimal(8,5)</code>. Since 5 digits after the decimal is more than needed, this eliminates the rounding issue.</p>
  
  <p>However, whenever I print this value in a C# ASP.NET application, it is always formatted with 5 digits after the decimal (e.g. <code>12.34000</code>). I don't understand this. When I read the value from the database, I assign it to a regular <code>decimal</code> value. So how does the <code>decimal</code> value "know" there should be 5 digits after the decimal point?</p>
  
  <p>More importantly, how can I display this value without the trailing zeros? I'm guessing there is a way to format the value. However, since it's used in many places it would be much better if it simply didn't automatically append trailing zeros. If needed, I can change the data type in the database.</p>