本文整理汇总了C#中System.Data.SqlTypes.SqlDecimal类的典型用法代码示例。如果您正苦于以下问题:C# SqlDecimal类的具体用法?C# SqlDecimal怎么用?C# SqlDecimal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SqlDecimal类属于System.Data.SqlTypes命名空间,在下文中一共展示了SqlDecimal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SqlDecimalBase
protected SqlDecimalBase(SqlDecimalAny d, byte precision, byte scale)
{
if (d != null)
{
_d = SqlDecimal.ConvertToPrecScale(d._d, precision, scale);
}
}
开发者ID:kellyselden,项目名称:Libraries,代码行数:7,代码来源:SqlDecimalBase.cs
示例2: Create
public void Create ()
{
// SqlDecimal (decimal)
SqlDecimal Test = new SqlDecimal (30.3098m);
Assert.AreEqual ((decimal) 30.3098, Test.Value, "#A01");
try {
decimal d = Decimal.MaxValue;
SqlDecimal test = new SqlDecimal (d + 1);
Assert.Fail ("#A02");
} catch (OverflowException e) {
Assert.AreEqual (typeof (OverflowException), e.GetType (), "#A03");
}
// SqlDecimal (double)
Test = new SqlDecimal (10E+10d);
Assert.AreEqual (100000000000.00000m, Test.Value, "#A05");
try {
SqlDecimal test = new SqlDecimal (10E+200d);
Assert.Fail ("#A06");
} catch (OverflowException e) {
Assert.AreEqual (typeof (OverflowException), e.GetType (), "#A07");
}
// SqlDecimal (int)
Test = new SqlDecimal (-1);
Assert.AreEqual (-1m, Test.Value, "#A08");
// SqlDecimal (long)
Test = new SqlDecimal ((long) (-99999));
Assert.AreEqual (-99999m, Test.Value, "#A09");
// SqlDecimal (byte, byte, bool. int[]
Test = new SqlDecimal (10, 3, false, new int [4] { 200, 1, 0, 0 });
Assert.AreEqual (-4294967.496m, Test.Value, "#A10");
try {
Test = new SqlDecimal (100, 100, false,
new int [4] {Int32.MaxValue,
Int32.MaxValue, Int32.MaxValue,
Int32.MaxValue});
Assert.Fail ("#A11");
} catch (SqlTypeException) {
}
// sqlDecimal (byte, byte, bool, int, int, int, int)
Test = new SqlDecimal (12, 2, true, 100, 100, 0, 0);
Assert.AreEqual (4294967297.00m, Test.Value, "#A13");
try {
Test = new SqlDecimal (100, 100, false,
Int32.MaxValue,
Int32.MaxValue, Int32.MaxValue,
Int32.MaxValue);
Assert.Fail ("#A14");
} catch (SqlTypeException) {
}
}
开发者ID:jamescourtney,项目名称:mono,代码行数:59,代码来源:SqlDecimalTest.cs
示例3: GetReady
public void GetReady()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
Test1 = new SqlDecimal (6464.6464m);
Test2 = new SqlDecimal (10000.00m);
Test3 = new SqlDecimal (10000.00m);
Test4 = new SqlDecimal (-6m);
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:SqlDecimalTest.cs
示例4: GetReady
public void GetReady ()
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
Test1 = new SqlDecimal (6464.6464m);
Test2 = new SqlDecimal (10000.00m);
Test3 = new SqlDecimal (10000.00m);
Test4 = new SqlDecimal (-6m);
Test5 = new SqlDecimal (Decimal.MaxValue);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:9,代码来源:SqlDecimalTest.cs
示例5: GetReady
public void GetReady ()
{
originalCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
Test1 = new SqlDecimal (6464.6464m);
Test2 = new SqlDecimal (10000.00m);
Test3 = new SqlDecimal (10000.00m);
Test4 = new SqlDecimal (-6m);
Test5 = new SqlDecimal (Decimal.MaxValue);
}
开发者ID:jamescourtney,项目名称:mono,代码行数:10,代码来源:SqlDecimalTest.cs
示例6: SqlDecimalTest
public SqlDecimalTest()
{
_originalCulture = CultureInfo.CurrentCulture; ;
CultureInfo.CurrentCulture = new CultureInfo("en-US");
_test1 = new SqlDecimal(6464.6464m);
_test2 = new SqlDecimal(10000.00m);
_test3 = new SqlDecimal(10000.00m);
_test4 = new SqlDecimal(-6m);
_test5 = new SqlDecimal(decimal.MaxValue);
}
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:SqlDecimalTest.cs
示例7: ToDecimal
private static Decimal ToDecimal(SqlDecimal value)
{
var data = value.Data;
var scale = value.Scale;
if (data[3] != 0 || scale > 28)
{
var result = decimal.Parse(value.ToString());
return result;
}
return new Decimal(data[0], data[1], data[2], !value.IsPositive, scale);
}
开发者ID:ciker,项目名称:Shaolinq,代码行数:14,代码来源:SqlServerDecimalDataType.cs
示例8: 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
示例9: 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
示例10: DecimalDiv
private static SqlDecimal DecimalDiv(SqlDecimal x, SqlDecimal y)
{
ulong lo = 0;
ulong hi = 0;
int sc = 0; // scale
int texp = 0;
byte prec = 0; // precision
bool positive = ! (x.positive ^ y.positive);
prec = x.Precision >= y.Precision ? x.Precision : y.Precision;
DecimalDivSub(ref x, ref y, ref lo, ref hi, ref texp);
sc = x.Scale - y.Scale;
Rescale128(ref lo, ref hi, ref sc, texp, 0, 38, 1);
uint r = 0;
while (prec < sc)
{
Div128By32(ref hi, ref lo, 10, ref r);
sc--;
}
if (r >= 5)
{
lo++;
}
while (((hi)*Math.Pow(2, 64) + lo) - Math.Pow(10, prec) > 0)
{
prec++;
}
while ((prec + sc) > MaxScale)
{
Div128By32(ref hi, ref lo, 10, ref r);
sc--;
if (r >= 5)
{
lo++;
}
}
var resultLo = (int) lo;
var resultMi = (int) (lo >> 32);
var resultMi2 = (int) (hi);
var resultHi = (int) (hi >> 32);
return new SqlDecimal(prec, (byte) sc, positive, resultLo,
resultMi, resultMi2,
resultHi);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:52,代码来源:SqlDecimal.cs
示例11: Sign
public static SqlInt32 Sign(SqlDecimal n)
{
if (n.IsNull)
{
return SqlInt32.Null;
}
return (n.IsPositive ? 1 : -1);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:8,代码来源:SqlDecimal.cs
示例12: Power
public static SqlDecimal Power(SqlDecimal n, double exp)
{
if (n.IsNull)
{
return Null;
}
return new SqlDecimal(Math.Pow(n.ToDouble(), exp));
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:9,代码来源:SqlDecimal.cs
示例13: Multiply
public static SqlDecimal Multiply(SqlDecimal x, SqlDecimal y)
{
return (x*y);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例14: LessThan
public static SqlBoolean LessThan(SqlDecimal x, SqlDecimal y)
{
return (x < y);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例15: GreaterThan
public static SqlBoolean GreaterThan(SqlDecimal x, SqlDecimal y)
{
return (x > y);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例16: Divide
public static SqlDecimal Divide(SqlDecimal x, SqlDecimal y)
{
return (x/y);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例17: Floor
public static SqlDecimal Floor(SqlDecimal n)
{
return AdjustScale(n, -(n.Scale), false);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例18: SqlDecimal
public static SqlDecimal operator -(SqlDecimal x, SqlDecimal y)
{
if (x.IsNull || y.IsNull)
{
return Null;
}
if (x.IsPositive && !y.IsPositive)
{
y = new SqlDecimal(y.Precision, y.Scale, !y.IsPositive, y.Data);
return x + y;
}
if (!x.IsPositive && y.IsPositive)
{
x = new SqlDecimal(x.Precision, x.Scale, !x.IsPositive, x.Data);
x = (x + y);
return new SqlDecimal(x.Precision, x.Scale, false, x.Data);
}
if (!x.IsPositive && !y.IsPositive)
{
y = new SqlDecimal(y.Precision, y.Scale, !y.IsPositive, y.Data);
x = new SqlDecimal(x.Precision, x.Scale, !x.IsPositive, x.Data);
return (y - x);
}
// adjust the scale to the larger of the two beforehand
if (x.scale > y.scale)
{
y = AdjustScale(y, x.scale - y.scale, false);
}
else if (y.scale > x.scale)
{
x = AdjustScale(x, y.scale - x.scale, false);
}
//calculation of the new Precision for the result
var resultPrecision = (byte) (Math.Max(x.Scale, y.Scale) +
Math.Max(x.Precision - x.Scale, y.Precision - y.Scale));
int[] op1_Data;
int[] op2_Data;
if (x >= y)
{
op1_Data = x.Data;
op2_Data = y.Data;
}
else
{
op1_Data = y.Data;
op2_Data = x.Data;
}
ulong res = 0;
int carry = 0;
var resultBits = new int[4];
/*
if ((uint)op2_Data [i] > (uint)op1_Data [i]) {
carry = UInt32.MaxValue;
op2_Data [i] = op2_Data [i] >> 1;
} else
carr = 0;
res = (uint)carry; +(ulong)((uint)op1_Data [i]) - (ulong)((uint)op2_Data [i])
*/
for (int i = 0; i < 4; i += 1)
{
res = ((uint) op1_Data[i]) - (ulong) ((uint) op2_Data[i]) + (ulong) carry;
carry = 0;
if ((uint) op2_Data[i] > (uint) op1_Data[i])
{
carry = -1;
}
resultBits[i] = (int) res;
}
if (carry > 0)
{
throw new OverflowException();
}
else
{
return new SqlDecimal(resultPrecision, x.Scale, (x >= y).Value, resultBits);
}
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:85,代码来源:SqlDecimal.cs
示例19: GreaterThanOrEqual
public static SqlBoolean GreaterThanOrEqual(SqlDecimal x, SqlDecimal y)
{
return (x >= y);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:4,代码来源:SqlDecimal.cs
示例20: Abs
public static SqlDecimal Abs(SqlDecimal n)
{
if (!n.notNull)
{
return n;
}
return new SqlDecimal(n.Precision, n.Scale, true, n.Data);
}
开发者ID:tohosnet,项目名称:Mono.Data.Sqlite,代码行数:8,代码来源:SqlDecimal.cs
注:本文中的System.Data.SqlTypes.SqlDecimal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论