Exemplo n.º 1
0
    static bool Math_Round__Double__MidpointRounding(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 2)
        {
            System.Double           arg0 = (System.Double)JSApi.getDouble((int)JSApi.GetType.Arg);
            System.MidpointRounding arg1 = (System.MidpointRounding)JSApi.getEnum((int)JSApi.GetType.Arg);
            JSApi.setDouble((int)JSApi.SetType.Rval, (System.Double)(System.Math.Round(arg0, arg1)));
        }

        return(true);
    }
Exemplo n.º 2
0
    static bool Math_Round__Decimal__MidpointRounding(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 2)
        {
            System.Decimal          arg0 = (System.Decimal)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            System.MidpointRounding arg1 = (System.MidpointRounding)JSApi.getEnum((int)JSApi.GetType.Arg);
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, System.Math.Round(arg0, arg1));
        }

        return(true);
    }
Exemplo n.º 3
0
        /// <summary>
        /// Rounds the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="RoundMode">The round mode.</param>
        /// <param name="decimals">The decimals.</param>
        /// <param name="MidPointRounding">The mid point rounding.</param>
        /// <returns></returns>
        public static decimal Round(decimal value, Calc.RoundMode RoundMode, int decimals, System.MidpointRounding MidPointRounding)
        {
            switch (RoundMode)
            {
            case RoundMode.RoundUp:
                decimal OriginalDecimal = default(decimal);
                if (decimals == 0)
                {
                    OriginalDecimal = value;
                    value           = Math.Truncate(value);
                    if (OriginalDecimal != value)
                    {
                        value = value + 1;
                    }
                }
                else
                {
                    decimal MultiplyPower = Convert.ToDecimal(Math.Pow(10, decimals));
                    value           = value * MultiplyPower;
                    OriginalDecimal = value;
                    value           = Math.Truncate(value);
                    if (OriginalDecimal != value)
                    {
                        value = value + 1;
                    }
                    value = SafeDiv(value, MultiplyPower);
                }

                return(value);

            case RoundMode.RoundDown:
                if (decimals == 0)
                {
                    value = Math.Truncate(value);
                }
                else
                {
                    decimal MultiplyPower = Convert.ToDecimal(Math.Pow(10, decimals));
                    value = value * MultiplyPower;
                    value = Math.Truncate(value);
                    value = SafeDiv(value, MultiplyPower);
                }

                return(value);

            case RoundMode.RoundUpOrDown:
                return(Math.Round(value, decimals, MidPointRounding));
            }

            //Should never happen
            return(0);
        }
Exemplo n.º 4
0
 public static System.Decimal Round(System.Decimal d, System.Int32 decimals, System.MidpointRounding mode)
 {
     return(0);
 }
Exemplo n.º 5
0
 public static System.Double Round(System.Double value, System.Int32 digits, System.MidpointRounding mode)
 {
     return(0);
 }