本文整理汇总了C#中System.Data.SqlTypes.SqlDecimal.MultByULong方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDecimal.MultByULong方法的具体用法?C# SqlDecimal.MultByULong怎么用?C# SqlDecimal.MultByULong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlTypes.SqlDecimal
的用法示例。
在下文中一共展示了SqlDecimal.MultByULong方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Round
private static SqlDecimal Round(SqlDecimal n, int lPosition, bool fTruncate)
{
if (n.IsNull)
return SqlDecimal.Null;
if (lPosition >= 0)
{
//If round to the right of decimal number
lPosition = Math.Min(s_NUMERIC_MAX_PRECISION, lPosition);
if (lPosition >= n.m_bScale)
return n; //No need to round
}
else
{
//If round to the left of the decimal point
lPosition = Math.Max(-s_NUMERIC_MAX_PRECISION, lPosition);
//Return +0.00 if truncation of integer part
if (lPosition < n.m_bScale - n.m_bPrec)
{
n.SetToZero();
return n;
}
}
uint ulRem = 0; // Remainder: the highest significant digit to be truncated
int lAdjust = Math.Abs(lPosition - (int)n.m_bScale); // Precision adjustment
uint ulLastDivBase = 1; //
//Compute the integral part of the numeric
while (lAdjust > 0)
{
if (lAdjust >= 9)
{
ulRem = n.DivByULong(s_rgulShiftBase[8]);
ulLastDivBase = s_rgulShiftBase[8];
lAdjust -= 9;
}
else
{
ulRem = n.DivByULong(s_rgulShiftBase[lAdjust - 1]);
ulLastDivBase = s_rgulShiftBase[lAdjust - 1];
lAdjust = 0;
}
}
// The rounding only depends on the first digit after the rounding position
if (ulLastDivBase > 1)
{
ulRem /= (ulLastDivBase / 10);
}
//If result is zero, return
if (n.FZero() && (fTruncate || ulRem < 5))
{
n.SetPositive();
n.AssertValid();
return n;
}
// Adjust by adding 1 if remainder is larger than 5
if (ulRem >= 5 && !fTruncate)
n.AddULong(1);
// Convert back to original scale
lAdjust = Math.Abs(lPosition - n.m_bScale);
while (lAdjust-- > 0)
{
n.MultByULong(s_ulBase10);
}
n.AssertValid();
return n;
}
示例2: Round
private static SqlDecimal Round(SqlDecimal n, int lPosition, bool fTruncate)
{
if (n.IsNull)
{
return Null;
}
if (lPosition >= 0)
{
lPosition = Math.Min(NUMERIC_MAX_PRECISION, lPosition);
if (lPosition >= n.m_bScale)
{
return n;
}
}
else
{
lPosition = Math.Max(-NUMERIC_MAX_PRECISION, lPosition);
if (lPosition < (n.m_bScale - n.m_bPrec))
{
n.SetToZero();
return n;
}
}
uint num2 = 0;
int num = Math.Abs((int) (lPosition - n.m_bScale));
uint num3 = 1;
while (num > 0)
{
if (num >= 9)
{
num2 = n.DivByULong(x_rgulShiftBase[8]);
num3 = x_rgulShiftBase[8];
num -= 9;
}
else
{
num2 = n.DivByULong(x_rgulShiftBase[num - 1]);
num3 = x_rgulShiftBase[num - 1];
num = 0;
}
}
if (num3 > 1)
{
num2 /= num3 / 10;
}
if (n.FZero() && (fTruncate || (num2 < 5)))
{
n.SetPositive();
return n;
}
if ((num2 >= 5) && !fTruncate)
{
n.AddULong(1);
}
num = Math.Abs((int) (lPosition - n.m_bScale));
while (num-- > 0)
{
n.MultByULong(x_ulBase10);
}
return n;
}