internal Exception CheckTotalAndFractionDigits(decimal value, int totalDigits, int fractionDigits, bool checkTotal, bool checkFraction) {
decimal maxValue = FacetsChecker.Power(10, totalDigits) - 1; //(decimal)Math.Pow(10, totalDigits) - 1 ;
int powerCnt = 0;
if (value < 0) {
value = Decimal.Negate(value); //Need to compare maxValue allowed against the absolute value
}
while (Decimal.Truncate(value) != value) { //Till it has a fraction
value = value * 10;
powerCnt++;
}
if (checkTotal && (value > maxValue || powerCnt > totalDigits)) {
return new XmlSchemaException(Res.Sch_TotalDigitsConstraintFailed, string.Empty);
}
if (checkFraction && powerCnt > fractionDigits) {
return new XmlSchemaException(Res.Sch_FractionDigitsConstraintFailed, string.Empty);
}
return null;
}
}