コード例 #1
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static Decimal Round(Decimal d, int decimals, MidpointRounding mode)
        {
            if (decimals < 0 || decimals > 28)
            {
                throw new ArgumentOutOfRangeException("decimals", SR.ArgumentOutOfRange_DecimalRound);
            }
            if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero)
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, "MidpointRounding"), "mode");
            }
            Contract.EndContractBlock();

            if (mode == MidpointRounding.ToEven)
            {
                Decimal result = new Decimal();
                if (DecCalc.VarDecRound(ref d, decimals, ref result) < 0)
                {
                    throw new OverflowException(SR.Overflow_Decimal);
                }

                d = result;
            }
            else
            {
                DecCalc.InternalRoundFromZero(ref d, decimals);
            }
            return(d);
        }
コード例 #2
0
        public static Decimal Round(Decimal d, int decimals)
        {
            Decimal result = new Decimal();

            if (decimals < 0 || decimals > 28)
            {
                throw new ArgumentOutOfRangeException(nameof(decimals), SR.ArgumentOutOfRange_DecimalRound);
            }

            DecCalc.VarDecRound(ref d, decimals, ref result);

            d = result;
            return(d);
        }
コード例 #3
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        internal static Decimal Round(Decimal d, int decimals)
        {
            Decimal result = new Decimal();

            if (decimals < 0 || decimals > 28)
            {
                throw new ArgumentOutOfRangeException("decimals", SR.ArgumentOutOfRange_DecimalRound);
            }

            if (DecCalc.VarDecRound(ref d, decimals, ref result) < 0)
            {
                throw new OverflowException(SR.Overflow_Decimal);
            }

            d = result;
            return(d);
        }
コード例 #4
0
ファイル: Decimal.cs プロジェクト: 952208166/corert
        public static Decimal Round(Decimal d, int decimals, MidpointRounding mode)
        {
            if (decimals < 0 || decimals > 28)
            {
                throw new ArgumentOutOfRangeException(nameof(decimals), SR.ArgumentOutOfRange_DecimalRound);
            }
            if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero)
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, "MidpointRounding"), nameof(mode));
            }

            if (mode == MidpointRounding.ToEven)
            {
                Decimal result = new Decimal();
                DecCalc.VarDecRound(ref d, decimals, ref result);
                d = result;
            }
            else
            {
                DecCalc.InternalRoundFromZero(ref d, decimals);
            }
            return(d);
        }