System.Xml.Schema.FacetsChecker.Power C# (CSharp) Méthode

Power() static private méthode

static private Power ( int x, int y ) : decimal
x int
y int
Résultat decimal
        internal static decimal Power(int x, int y) {
            //Returns X raised to the power Y
            decimal returnValue = 1m;
            decimal decimalValue = (decimal)x;
            if ( y > 28 ) { //CLR decimal cannot handle more than 29 digits (10 power 28.)
                return decimal.MaxValue;
            }
            for (int i = 0; i < y; i++) {
                returnValue = returnValue * decimalValue;
            }
            return returnValue;
        }
    }

Usage Example

        internal Exception CheckTotalAndFractionDigits(decimal value, int totalDigits, int fractionDigits, bool checkTotal, bool checkFraction)
        {
            decimal num  = decimal.op_Decrement(FacetsChecker.Power(10, totalDigits));
            int     num2 = 0;

            if (value < 0M)
            {
                value = decimal.Negate(value);
            }
            while (decimal.Truncate(value) != value)
            {
                value *= 10M;
                num2++;
            }
            if (checkTotal && ((value > num) || (num2 > totalDigits)))
            {
                return(new XmlSchemaException("Sch_TotalDigitsConstraintFailed", string.Empty));
            }
            if (checkFraction && (num2 > fractionDigits))
            {
                return(new XmlSchemaException("Sch_FractionDigitsConstraintFailed", string.Empty));
            }
            return(null);
        }