当前位置: 首页>>代码示例>>C#>>正文


C# SqlDecimal.AdjustScale方法代码示例

本文整理汇总了C#中System.Data.SqlTypes.SqlDecimal.AdjustScale方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDecimal.AdjustScale方法的具体用法?C# SqlDecimal.AdjustScale怎么用?C# SqlDecimal.AdjustScale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlTypes.SqlDecimal的用法示例。


在下文中一共展示了SqlDecimal.AdjustScale方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SqlMoney

 public SqlMoney(decimal value)
 {
     SqlDecimal num2 = new SqlDecimal(value);
     num2.AdjustScale(x_iMoneyScale - num2.Scale, true);
     if ((num2.m_data3 != 0) || (num2.m_data4 != 0))
     {
         throw new OverflowException(SQLResource.ArithOverflowMessage);
     }
     bool isPositive = num2.IsPositive;
     ulong num = num2.m_data1 + (num2.m_data2 << 0x20);
     if ((isPositive && (num > 0x7fffffffffffffffL)) || (!isPositive && (num > 9223372036854775808L)))
     {
         throw new OverflowException(SQLResource.ArithOverflowMessage);
     }
     this.m_value = isPositive ? ((long) num) : ((long) -num);
     this.m_fNotNull = true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:SqlMoney.cs

示例2: SqlMoney

        /// <summary>
        /// Initializes a new instance of the <see cref='SqlMoney'/> class with the value given.
        /// </summary>
        public SqlMoney(decimal value)
        {
            // Since Decimal is a value type, operate directly on value, don't worry about changing it.
            SqlDecimal snum = new SqlDecimal(value);
            snum.AdjustScale(s_iMoneyScale - snum.Scale, true);
            Debug.Assert(snum.Scale == s_iMoneyScale);

            if (snum._data3 != 0 || snum._data4 != 0)
                throw new OverflowException(SQLResource.s_arithOverflowMessage);

            bool fPositive = snum.IsPositive;
            ulong ulValue = snum._data1 + (((ulong)snum._data2) << 32);
            if (fPositive && ulValue > long.MaxValue ||
                !fPositive && ulValue > unchecked((ulong)(long.MinValue)))
                throw new OverflowException(SQLResource.s_arithOverflowMessage);

            _value = fPositive ? (long)ulValue : unchecked(-(long)ulValue);
            _fNotNull = true;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:22,代码来源:SQLMoney.cs

示例3: Power

        // Power - Compute the power of a numeric
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static SqlDecimal Power(SqlDecimal n, double exp)
        {
            n.AssertValid();

            if (n.IsNull)
                return SqlDecimal.Null;

            byte prec = n.Precision;
            int scale = n.Scale;
            double dBaseNum = n.ToDouble();

            n = new SqlDecimal(Math.Pow(dBaseNum, exp));
            n.AdjustScale(scale - (int)n.Scale, true);

            n.m_bPrec = MaxPrecision;

            return n;
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:22,代码来源:SQLDecimal.cs

示例4: result


//.........这里部分代码省略.........
            // Calculate actual result length
            culRes = idRes + 1;

            // III) Adjust precision,scale to result prec,scale
            if (lScaleAdjust != 0)
            {
                // If need to decrease scale
                if (lScaleAdjust < 0)
                {
                    Debug.Assert(s_NUMERIC_MAX_PRECISION == ResPrec);

                    // have to adjust - might yet end up fitting.
                    // Cannot call AdjustScale - number cannot fit in a numeric, so
                    // have to duplicate code here

                    uint ulRem;          //Remainder when downshifting
                    uint ulShiftBase;    //What to multiply by to effect scale adjust

                    do
                    {
                        if (lScaleAdjust <= -9)
                        {
                            ulShiftBase = s_rgulShiftBase[8];
                            lScaleAdjust += 9;
                        }
                        else
                        {
                            ulShiftBase = s_rgulShiftBase[-lScaleAdjust - 1];
                            lScaleAdjust = 0;
                        }
                        MpDiv1(rgulRes, ref culRes, ulShiftBase, out ulRem);
                    }
                    while (lScaleAdjust != 0);

                    // Still do not fit?
                    if (culRes > s_cNumeMax)
                        throw new OverflowException(SQLResource.ArithOverflowMessage);

                    for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                        rgulRes[idRes] = 0;
                    ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ResScale, fResPositive);

                    // Is it greater than 10**38?
                    if (ret.FGt10_38())
                        throw new OverflowException(SQLResource.ArithOverflowMessage);

                    ret.AssertValid();

                    // If remainder is 5 or above, increment/decrement by 1.
                    if (ulRem >= ulShiftBase / 2)
                        ret.AddULong(1);
                    // After adjusting, if the result is 0 and remainder is less than 5,
                    // set the sign to be positive
                    if (ret.FZero())
                        ret.SetPositive();

                    return ret;
                }

                // Otherwise call AdjustScale
                if (culRes > s_cNumeMax)    // Do not fit now, so will not fit after adjustment
                    throw new OverflowException(SQLResource.ArithOverflowMessage);
                // NOTE: Have not check for value in the range (10**38..2**128),
                // as we'll call AdjustScale with positive argument, and it'll
                // return "normal" overflow

                for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                    rgulRes[idRes] = 0;
                ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ActualScale, fResPositive);

                if (ret.FZero())
                    ret.SetPositive();

                ret.AssertValid();

                ret.AdjustScale(lScaleAdjust, true);

                return ret;
            }
            else
            {
                if (culRes > s_cNumeMax)
                    throw new OverflowException(SQLResource.ArithOverflowMessage);

                for (idRes = culRes; idRes < s_cNumeMax; idRes++)
                    rgulRes[idRes] = 0;
                ret = new SqlDecimal(rgulRes, (byte)culRes, (byte)ResPrec, (byte)ResScale, fResPositive);

                // Is it greater than 10**38?
                if (ret.FGt10_38())
                    throw new OverflowException(SQLResource.ArithOverflowMessage);

                if (ret.FZero())
                    ret.SetPositive();

                ret.AssertValid();

                return ret;
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:101,代码来源:SQLDecimal.cs

示例5: while


//.........这里部分代码省略.........
             if (num2 < num7)
             {
                 num7 = x_ulInt32Base;
             }
             else
             {
                 num7 = 0L;
             }
             rgulU[index++] = (uint) num2;
             num2 = (num2 >> 0x20) + num7;
         }
         if (num2 != 0L)
         {
             rgulU[index++] = (uint) num2;
         }
     }
     while ((rgulU[index] == 0) && (index > 0))
     {
         index--;
     }
     int ciulU = index + 1;
     if (digits != 0)
     {
         if (digits < 0)
         {
             uint num12;
             uint num14;
             do
             {
                 if (digits <= -9)
                 {
                     num12 = x_rgulShiftBase[8];
                     digits += 9;
                 }
                 else
                 {
                     num12 = x_rgulShiftBase[-digits - 1];
                     digits = 0;
                 }
                 MpDiv1(rgulU, ref ciulU, num12, out num14);
             }
             while (digits != 0);
             if (ciulU > x_cNumeMax)
             {
                 throw new OverflowException(SQLResource.ArithOverflowMessage);
             }
             for (index = ciulU; index < x_cNumeMax; index++)
             {
                 rgulU[index] = 0;
             }
             num11 = new SqlDecimal(rgulU, (byte) ciulU, (byte) num6, (byte) num3, fPositive);
             if (num11.FGt10_38())
             {
                 throw new OverflowException(SQLResource.ArithOverflowMessage);
             }
             if (num14 >= (num12 / 2))
             {
                 num11.AddULong(1);
             }
             if (num11.FZero())
             {
                 num11.SetPositive();
             }
             return num11;
         }
         if (ciulU > x_cNumeMax)
         {
             throw new OverflowException(SQLResource.ArithOverflowMessage);
         }
         for (index = ciulU; index < x_cNumeMax; index++)
         {
             rgulU[index] = 0;
         }
         num11 = new SqlDecimal(rgulU, (byte) ciulU, (byte) num6, (byte) num10, fPositive);
         if (num11.FZero())
         {
             num11.SetPositive();
         }
         num11.AdjustScale(digits, true);
         return num11;
     }
     if (ciulU > x_cNumeMax)
     {
         throw new OverflowException(SQLResource.ArithOverflowMessage);
     }
     for (index = ciulU; index < x_cNumeMax; index++)
     {
         rgulU[index] = 0;
     }
     num11 = new SqlDecimal(rgulU, (byte) ciulU, (byte) num6, (byte) num3, fPositive);
     if (num11.FGt10_38())
     {
         throw new OverflowException(SQLResource.ArithOverflowMessage);
     }
     if (num11.FZero())
     {
         num11.SetPositive();
     }
     return num11;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:SqlDecimal.cs

示例6: Power

 public static SqlDecimal Power(SqlDecimal n, double exp)
 {
     if (n.IsNull)
     {
         return Null;
     }
     byte precision = n.Precision;
     int scale = n.Scale;
     double x = n.ToDouble();
     n = new SqlDecimal(Math.Pow(x, exp));
     n.AdjustScale(scale - n.Scale, true);
     n.m_bPrec = MaxPrecision;
     return n;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:SqlDecimal.cs


注:本文中的System.Data.SqlTypes.SqlDecimal.AdjustScale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。