*                   responsible for reporting the error to the user through
   *                   ValidationEventHandler.
   */
  private IMetadataType convert(Number v) throws Exception {
    /**
     * Validate the max/min values.
     */
    if (minInclusive != null && v.doubleValue() < minInclusive) {
      throw new Exception("minimum value violation " + this.getClass().getSimpleName().replace(NAME_PREFIX, "") + " [" + minInclusive + "] for \"" + v + "\".");
    }
    if (maxInclusive != null && v.doubleValue() > maxInclusive) {
      throw new Exception("maximum value violation " + this.getClass().getSimpleName().replace(NAME_PREFIX, "") + " [" + maxInclusive + "] for \"" + v + "\".");
    }
    /**
     * Validate the digit count.
     */
    if (v instanceof BigInteger) {
      if (totalDigits != null && totalDigits < getDigitCount((BigInteger) v)) {
        throw new Exception("maximum digits violation " + this.getClass().getSimpleName().replace(NAME_PREFIX, "") + " [" + totalDigits + "] for \"" + v + "\".");
      }
      return new TInteger((BigInteger) v);
    } else if (v instanceof BigDecimal || v instanceof Double) {
      /**
       * Just convert the number precision to ensure it matches the required XML
       * style pattern.
       */
      return new TDecimal(new BigDecimal(v.doubleValue()).setScale(totalDigits - fractionDigits, RoundingMode.HALF_UP));
    }
    /**
     * Default fall through is a Double type.
     */
    return new TDouble((Double) v);
  }