2 // System.Data.SqlTypes.SqlDecimal
5 // Tim Coleman <tim@timcoleman.com>
7 // (C) Copyright 2002 Tim Coleman
12 namespace System.Data.SqlTypes
14 public struct SqlDecimal : INullable, IComparable
18 private decimal value;
20 public static readonly byte MaxPrecision = 38;
21 public static readonly byte MaxScale = 28;
22 public static readonly SqlDecimal MaxValue = new SqlDecimal (79228162514264337593543950335.0);
23 public static readonly SqlDecimal MinValue = new SqlDecimal (-79228162514264337593543950335.0);
24 public static readonly SqlDecimal Null;
30 public SqlDecimal (decimal value)
35 public SqlDecimal (double value)
37 this.value = ((decimal)value);
40 public SqlDecimal (int value)
42 this.value = ((decimal)value);
45 public SqlDecimal (long value)
47 this.value = ((decimal)value);
51 public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int[] bits)
53 throw new NotImplementedException ();
57 public SqlDecimal (byte bPrecision, byte bScale, bool fPositive, int data1, int data2, int data3, int data4)
59 throw new NotImplementedException ();
67 public byte[] BinData {
68 get { throw new NotImplementedException (); }
74 throw new SqlNullValueException ();
76 return Decimal.GetBits (value);
81 get { return (bool) (this == Null); }
84 public bool IsPositive {
85 get { return (this.Value > 0); }
89 public byte Precision {
90 get { throw new NotImplementedException (); }
95 get { throw new NotImplementedException (); }
98 public decimal Value {
101 throw new SqlNullValueException ();
112 public static SqlDecimal Abs (SqlDecimal n)
114 throw new NotImplementedException();
117 public static SqlDecimal Add (SqlDecimal x, SqlDecimal y)
123 public static SqlDecimal AdjustScale (SqlDecimal n, int digits, bool fRound)
125 throw new NotImplementedException ();
129 public static SqlDecimal Ceiling (SqlDecimal n)
131 throw new NotImplementedException();
134 public int CompareTo (object value)
138 else if (!(value is SqlDecimal))
139 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlDecimal"));
140 else if (value.IsNull)
143 return value.CompareTo (value.Value);
147 public static SqlDecimal ConvertToPrecScale (SqlDecimal n, int precision, int scale)
149 throw new NotImplementedException ();
152 public static SqlDecimal Divide (SqlDecimal x, SqlDecimal y)
157 public override bool Equals (object value)
159 if (!(value is SqlDecimal))
162 return (bool) (this == value);
165 public static SqlBoolean Equals (SqlDecimal x, SqlDecimal y)
171 public static SqlDecimal Floor (SqlDecimal n)
173 throw new NotImplementedException ();
177 public override int GetHashCode ()
182 public static SqlBoolean GreaterThan (SqlDecimal x, SqlDecimal y)
187 public static SqlBoolean GreaterThanOrEqual (SqlDecimal x, SqlDecimal y)
192 public static SqlBoolean LessThan (SqlDecimal x, SqlDecimal y)
197 public static SqlBoolean LessThanOrEqual (SqlDecimal x, SqlDecimal y)
202 public static SqlDecimal Multiply (SqlDecimal x, SqlDecimal y)
207 public static SqlBoolean NotEquals (SqlDecimal x, SqlDecimal y)
213 public static SqlDecimal Parse (string s)
215 throw new NotImplementedException ();
219 public static SqlDecimal Power (SqlDecimal n, double exp)
221 throw new NotImplementedException ();
225 public static SqlDecimal Round (SqlDecimal n, int position)
227 throw new NotImplementedException ();
231 public static SqlInt32 Sign (SqlDecimal n)
233 throw new NotImplementedException ();
236 public static SqlDecimal Subtract (SqlDecimal x, SqlDecimal y)
241 public double ToDouble ()
243 return ((double)value);
246 public SqlBoolean ToSqlBoolean ()
248 return ((SqlBoolean)this);
251 public SqlByte ToSqlByte ()
253 return ((SqlByte)this);
256 public SqlDouble ToSqlDouble ()
258 return ((SqlDouble)this);
261 public SqlInt16 ToSqlInt16 ()
263 return ((SqlInt16)this);
266 public SqlInt32 ToSqlInt32 ()
268 return ((SqlInt32)this);
271 public SqlInt64 ToSqlInt64 ()
273 return ((SqlInt64)this);
276 public SqlMoney ToSqlMoney ()
278 return ((SqlMoney)this);
281 public SqlSingle ToSqlSingle ()
283 return ((SqlSingle)this);
286 public SqlString ToSqlString ()
288 return ((SqlString)this);
291 public override string ToString ()
296 return value.ToString ();
300 public static SqlDecimal Truncate (SqlDecimal n, int position)
302 throw new NotImplementedException ();
305 public static SqlDecimal operator + (SqlDecimal x, SqlDecimal y)
307 return new SqlDecimal (x.Value + y.Value);
310 public static SqlDecimal operator / (SqlDecimal x, SqlDecimal y)
312 return new SqlDecimal (x.Value / y.Value);
315 public static SqlBoolean operator == (SqlDecimal x, SqlDecimal y)
317 if (x.IsNull || y.IsNull)
318 return SqlBoolean.Null;
320 return new SqlBoolean (x.Value == y.Value);
323 public static SqlBoolean operator > (SqlDecimal x, SqlDecimal y)
325 if (x.IsNull || y.IsNull)
326 return SqlBoolean.Null;
328 return new SqlBoolean (x.Value > y.Value);
331 public static SqlBoolean operator >= (SqlDecimal x, SqlDecimal y)
333 if (x.IsNull || y.IsNull)
334 return SqlBoolean.Null;
336 return new SqlBoolean (x.Value >= y.Value);
339 public static SqlBoolean operator != (SqlDecimal x, SqlDecimal y)
341 if (x.IsNull || y.IsNull)
342 return SqlBoolean.Null;
344 return new SqlBoolean (!(x.Value == y.Value));
347 public static SqlBoolean operator < (SqlDecimal x, SqlDecimal y)
349 if (x.IsNull || y.IsNull)
350 return SqlBoolean.Null;
352 return new SqlBoolean (x.Value < y.Value);
355 public static SqlBoolean operator <= (SqlDecimal x, SqlDecimal y)
357 if (x.IsNull || y.IsNull)
358 return SqlBoolean.Null;
360 return new SqlBoolean (x.Value <= y.Value);
363 public static SqlDecimal operator * (SqlDecimal x, SqlDecimal y)
365 return new SqlDecimal (x.Value * y.Value);
368 public static SqlDecimal operator - (SqlDecimal x, SqlDecimal y)
370 return new SqlDecimal (x.Value - y.Value);
373 public static SqlDecimal operator - (SqlDecimal n)
375 return new SqlDecimal (-(n.Value));
378 public static explicit operator SqlDecimal (SqlBoolean x)
383 return new SqlDecimal ((decimal)x.ByteValue);
386 public static explicit operator Decimal (SqlDecimal n)
391 public static explicit operator SqlDecimal (SqlDouble x)
396 return new SqlDecimal ((decimal)x.Value);
399 public static explicit operator SqlDecimal (SqlSingle x)
404 return new SqlDecimal ((decimal)x.Value);
408 public static explicit operator SqlDecimal (SqlString x)
410 throw new NotImplementedException ();
413 public static implicit operator SqlDecimal (decimal x)
415 return new SqlDecimal (x);
418 public static implicit operator SqlDecimal (SqlByte x)
423 return new SqlDecimal ((decimal)x.Value);
426 public static implicit operator SqlDecimal (SqlInt16 x)
431 return new SqlDecimal ((decimal)x.Value);
434 public static implicit operator SqlDecimal (SqlInt32 x)
439 return new SqlDecimal ((decimal)x.Value);
442 public static implicit operator SqlDecimal (SqlInt64 x)
447 return new SqlDecimal ((decimal)x.Value);
450 public static implicit operator SqlDecimal (SqlMoney x)
455 return new SqlDecimal ((decimal)x.Value);