title: How to make it so trailing zeros are not dropped in a decimal number in C#?
body: <p>I'm creating a <code>RandomDecimal</code> function that allows you to specify a max value and the precision of the decimal. However, if the last random digit that is chosen happens to be zero, it is dropped and the precision is off. Is it possible to not lose this zero? I tried converting it to a string then back to a decimal but it's still dropped.</p>
  
  <pre><code>    public static decimal RandomDecimal(int maxValue, int precision)
      {
          decimal result = new Random().Next(maxValue);
  
          if (maxValue == 0)
          {
              return result;
          }
  
          int i = 1;
  
          decimal digit = 0;
  
          while (i &lt;= precision)
          {
              digit = new Random().Next(10);
              digit = (digit / (Convert.ToDecimal(Math.Pow(10, i))));
              result = result + digit;
              i++;
          }
  
      //    if (digit == 0)
      //    {
      //     string resultstring = Convert.ToString(result) + '0';
     //      result = Convert.ToDecimal(resultstring);
     //       } This code doesn't do anything because the zero is still dropped.
  
          return result;
      }
  </code></pre>