title: Calculate System.Decimal Precision and Scale
body: <p>Suppose that we have a System.Decimal number.</p>
  
  <p>For illustration, let's take one whose ToString() representation is as follows:</p>
  
  <pre><code>d.ToString() = "123.4500"
  </code></pre>
  
  <p>The following can be said about this Decimal. For our purposes here, scale is defined as the number of digits to the right of the decimal point. Effective scale is similar but ignores any trailing zeros that occur in the fractional part. (In other words, these parameters are defined like SQL decimals plus some additional parameters to account for the System.Decimal concept of trailing zeros in the fractional part.)</p>
  
  <ul>
  <li>Precision: 7</li>
  <li>Scale:     4</li>
  <li>EffectivePrecision: 5</li>
  <li>EffectiveScale: 2</li>
  </ul>
  
  <p>Given an arbitrary System.Decimal, how can I compute all four of these parameters efficiently and without converting to a String and examining the String? The solution probably requires Decimal.GetBits.</p>
  
  <p>Some more examples:</p>
  
  <pre><code>Examples Precision  Scale  EffectivePrecision  EffectiveScale
  0        1 (?)      0      1 (?)               0
  0.0      2 (?)      1      1 (?)               0
  12.45    4          2      4                   2
  12.4500  6          4      4                   2
  770      3          0      3                   0
  </code></pre>
  
  <p>(?) Alternatively interpreting these precisions as zero would be fine.</p>