Example #1
0
        public static EsathCurrency PMT(ElfNumber rate, EsathNumber nper, EsathCurrency pv, EsathCurrency fv, EsathNumber type)
        {
            if (type != 0 && type != 1)
            {
                throw new ErroneousScriptRuntimeException(ElfExceptionType.OperandsDontSuitMethod, rate.VM);
            }

            if (rate is EsathCurrency)
            {
                throw new ErroneousScriptRuntimeException(ElfExceptionType.OperandsDontSuitMethod, rate.VM);
            }

            double result;
            if (rate == 0)
            {
                if (nper == 0)
                {
                    throw new ErroneousScriptRuntimeException(ElfExceptionType.DivisionByZero, rate.VM);
                }

                result = (-pv - fv) / nper;
            }
            else
            {
                result = (-pv * Math.Pow(1 + rate, nper) - fv) / ((1 + rate * type) * ((Math.Pow(1 + rate, nper) - 1) / rate));
            }

            return new EsathCurrency(result);
        }
Example #2
0
 public static ElfNumber RoundDown(this ElfNumber n, EsathNumber digits)
 {
     var val = n is EsathPercent ? n.Val * 100 : n.Val;
     return (ElfNumber)Activator.CreateInstance(n.GetType(), val.RoundDown((int)digits.Val));
 }