4 // Represents a floating-point decimal data type with up to 29
5 // significant digits, suitable for financial and commercial calculations.
8 // Martin Weindel (martin.weindel@t-online.de)
10 // (C) 2001 Martin Weindel
14 using System.Globalization;
16 using System.Runtime.CompilerServices;
18 using System.Runtime.InteropServices;
25 /// Represents a floating-point decimal data type with up to 29 significant
26 /// digits, suitable for financial and commercial calculations
29 public struct Decimal: IComparable, IFormattable, IConvertible
31 // LAMESPEC: the attributes aren't mentioned, but show up in CorCompare
32 // Unfortunately, corcompare starts throwing security exceptions when
33 // these attributes are present...
35 [DecimalConstantAttribute(0, 1, unchecked((uint)-1), unchecked((uint)-1), unchecked((uint)-1))]
36 public static readonly Decimal MinValue = new Decimal(-1, -1, -1, true, 0);
37 [DecimalConstantAttribute(0, 0, unchecked((uint)-1), unchecked((uint)-1), unchecked((uint)-1))]
38 public static readonly Decimal MaxValue = new Decimal(-1, -1, -1, false, 0);
39 [DecimalConstantAttribute(0, 1, 0, 0, 1)]
40 public static readonly Decimal MinusOne = new Decimal(1, 0, 0, true, 0);
41 [DecimalConstantAttribute(0, 0, 0, 0, 1)]
42 public static readonly Decimal One = new Decimal(1, 0, 0, false, 0);
43 [DecimalConstantAttribute(0, 0, 0, 0, 0)]
44 public static readonly Decimal Zero = new Decimal(0, 0, 0, false, 0);
46 // maximal decimal value as double
47 private static readonly double dDecMaxValue = 7.922816251426433759354395033e28;
48 // epsilon decimal value as double
49 private static readonly double dDecEpsilon = 0.5e-28; // == 0.5 * 1 / 10^28
52 private const int DECIMAL_DIVIDE_BY_ZERO = 5;
53 private const uint MAX_SCALE = 28;
54 private const int iMAX_SCALE = 28;
55 private const uint SIGN_FLAG = 0x80000000;
56 private const uint SCALE_MASK = 0x00FF0000;
57 private const int SCALE_SHIFT = 16;
58 private const uint RESERVED_SS32_BITS = 0x7F00FFFF;
60 // internal representation of decimal
66 // LAMESPEC: this constructor is missing in specification
67 // but exists in MS Csharp implementation
68 public Decimal(int lo, int mid, int hi, bool isNegative, byte scale)
76 if (scale > MAX_SCALE)
78 throw new ArgumentOutOfRangeException (Locale.GetText ("scale must be between 0 and 28"));
83 if (isNegative) ss32 |= SIGN_FLAG;
87 public Decimal(int val)
95 lo32 = ((uint)~val) + 1;
105 [CLSCompliant(false)]
106 public Decimal(uint val)
109 ss32 = hi32 = mid32 = 0;
112 public Decimal(long val)
120 ulong u = ((ulong)~val) + 1;
122 mid32 = (uint)(u >> 32);
127 ulong u = (ulong)val;
129 mid32 = (uint)(u >> 32);
134 [CLSCompliant(false)]
135 public Decimal(ulong uval)
141 mid32 = (uint)(uval >> 32);
145 public Decimal(float val)
147 if (double2decimal(out this, val, 7) != 0)
149 throw new OverflowException();
153 public Decimal(double val)
155 if (double2decimal(out this, val, 15) != 0)
157 throw new OverflowException();
161 public Decimal(int[] bits)
165 throw new ArgumentNullException(Locale.GetText ("Bits is a null reference"));
168 if (bits.GetLength(0) != 4)
170 throw new ArgumentException(Locale.GetText ("bits does not contain four values"));
174 lo32 = (uint) bits[0];
175 mid32 = (uint) bits[1];
176 hi32 = (uint) bits[2];
177 ss32 = (uint) bits[3];
178 byte scale = (byte)(ss32 >> SCALE_SHIFT);
179 if (scale > MAX_SCALE || (ss32 & RESERVED_SS32_BITS) != 0)
181 throw new ArgumentException(Locale.GetText ("Invalid bits[3]"));
186 public static decimal FromOACurrency(long cy)
188 return (decimal)cy / (decimal)10000;
191 public static int[] GetBits(Decimal d)
195 return new int[] { (int)d.lo32, (int)d.mid32, (int)d.hi32,
200 public static Decimal Negate(Decimal d)
207 public static Decimal Add(Decimal d1, Decimal d2)
209 if (decimalIncr(ref d1, ref d2) == 0)
212 throw new OverflowException(Locale.GetText ("Overflow on adding decimal number"));
215 public static Decimal Subtract(Decimal d1, Decimal d2)
217 d2.ss32 ^= SIGN_FLAG;
218 int result = decimalIncr(ref d1, ref d2);
222 throw new OverflowException(Locale.GetText ("Overflow on subtracting decimal numbers ("+result+")"));
225 public override int GetHashCode()
230 public static Decimal operator +(Decimal d1, Decimal d2)
235 public static Decimal operator --(Decimal d)
237 return Add(d, MinusOne);
240 public static Decimal operator ++(Decimal d)
245 public static Decimal operator -(Decimal d1, Decimal d2)
247 return Subtract(d1, d2);
250 public static Decimal operator -(Decimal d)
255 public static Decimal operator +(Decimal d)
260 public static Decimal operator *(Decimal d1, Decimal d2)
262 return Multiply(d1, d2);
265 public static Decimal operator /(Decimal d1, Decimal d2)
267 return Divide(d1, d2);
270 public static Decimal operator %(Decimal d1, Decimal d2)
272 return Remainder(d1, d2);
275 public static explicit operator byte(Decimal val)
279 if (decimal2UInt64(ref val, out result) != 0)
281 throw new System.OverflowException();
284 if (result > Byte.MaxValue || result < Byte.MinValue)
286 throw new System.OverflowException();
289 return (byte) result;
292 [CLSCompliant(false)]
293 public static explicit operator sbyte(Decimal val)
297 if (decimal2Int64(ref val, out result) != 0)
299 throw new System.OverflowException();
302 if (result > SByte.MaxValue || result < SByte.MinValue)
304 throw new System.OverflowException();
307 return (sbyte) result;
310 public static explicit operator char(Decimal val)
314 if (decimal2UInt64(ref val, out result) != 0)
316 throw new System.OverflowException();
319 if (result > Char.MaxValue || result < Char.MinValue)
321 throw new System.OverflowException();
324 return (char) result;
327 public static explicit operator short(Decimal val)
331 if (decimal2Int64(ref val, out result) != 0)
333 throw new System.OverflowException();
336 if (result > Int16.MaxValue || result < Int16.MinValue)
338 throw new System.OverflowException();
341 return (short) result;
344 [CLSCompliant(false)]
345 public static explicit operator ushort(Decimal val)
349 if (decimal2UInt64(ref val, out result) != 0)
351 throw new System.OverflowException();
354 if (result > UInt16.MaxValue || result < UInt16.MinValue)
356 throw new System.OverflowException();
359 return (ushort) result;
362 public static explicit operator int(Decimal val)
366 if (decimal2Int64(ref val, out result) != 0)
368 throw new System.OverflowException();
371 if (result > Int32.MaxValue || result < Int32.MinValue)
373 throw new System.OverflowException();
379 [CLSCompliant(false)]
380 public static explicit operator uint(Decimal val)
384 if (decimal2UInt64(ref val, out result) != 0)
386 throw new System.OverflowException();
389 if (result > UInt32.MaxValue || result < UInt32.MinValue)
391 throw new System.OverflowException();
394 return (uint) result;
397 public static explicit operator long(Decimal val)
401 if (decimal2Int64(ref val, out result) != 0)
403 throw new System.OverflowException();
409 [CLSCompliant(false)]
410 public static explicit operator ulong(Decimal val)
414 if (decimal2UInt64(ref val, out result) != 0)
416 throw new System.OverflowException();
422 public static implicit operator Decimal(byte val)
424 return new Decimal(val);
427 [CLSCompliant(false)]
428 public static implicit operator Decimal(sbyte val)
430 return new Decimal(val);
433 public static implicit operator Decimal(short val)
435 return new Decimal(val);
438 [CLSCompliant(false)]
439 public static implicit operator Decimal(ushort val)
441 return new Decimal(val);
444 public static implicit operator Decimal(char val)
446 return new Decimal(val);
449 public static implicit operator Decimal(int val)
451 return new Decimal(val);
454 [CLSCompliant(false)]
455 public static implicit operator Decimal(uint val)
457 return new Decimal(val);
460 public static implicit operator Decimal(long val)
462 return new Decimal(val);
465 [CLSCompliant(false)]
466 public static implicit operator Decimal(ulong val)
468 return new Decimal(val);
471 public static explicit operator Decimal(float val)
473 return new Decimal(val);
476 public static explicit operator Decimal(double val)
478 return new Decimal(val);
481 public static explicit operator float(Decimal val)
483 return (float) (double) val;
486 public static explicit operator double(Decimal val)
488 return decimal2double(ref val);
492 public static bool operator !=(Decimal d1, Decimal d2)
494 return !Equals(d1, d2);
497 public static bool operator ==(Decimal d1, Decimal d2)
499 return Equals(d1, d2);
502 public static bool operator >(Decimal d1, Decimal d2)
504 return decimalCompare(ref d1, ref d2) > 0;
507 public static bool operator >=(Decimal d1, Decimal d2)
509 return decimalCompare(ref d1, ref d2) >= 0;
512 public static bool operator <(Decimal d1, Decimal d2)
514 return decimalCompare(ref d1, ref d2) < 0;
517 public static bool operator <=(Decimal d1, Decimal d2)
519 return decimalCompare(ref d1, ref d2) <= 0;
522 public static bool Equals(Decimal d1, Decimal d2)
524 return decimalCompare(ref d1, ref d2) == 0;
527 public override bool Equals(object o)
532 return Equals((Decimal) o, this);
535 public static Decimal Floor(Decimal d)
537 decimalFloorAndTrunc(ref d, 1);
541 public static Decimal Truncate(Decimal d)
543 decimalFloorAndTrunc(ref d, 0);
547 public static Decimal Round(Decimal d, int decimals)
549 if (decimals < 0 || decimals > iMAX_SCALE)
551 throw new ArgumentOutOfRangeException(Locale.GetText ("decimals must be between 0 and 28"));
554 decimalRound(ref d, decimals);
558 public static Decimal Multiply(Decimal d1, Decimal d2)
560 if (decimalMult(ref d1, ref d2) != 0)
562 throw new OverflowException();
568 public static Decimal Divide(Decimal d1, Decimal d2)
570 if (d1 == 0 && d2 != 0) return 0;
573 int rc = decimalDiv(out d3, ref d1, ref d2);
577 if (rc == DECIMAL_DIVIDE_BY_ZERO)
578 throw new DivideByZeroException();
580 throw new OverflowException();
586 public static Decimal Remainder(Decimal d1, Decimal d2)
589 int rc = decimalIntDiv(out d3, ref d1, ref d2);
593 if (rc == DECIMAL_DIVIDE_BY_ZERO)
594 throw new DivideByZeroException();
596 throw new OverflowException();
602 public static int Compare(Decimal d1, Decimal d2)
604 return decimalCompare(ref d1, ref d2);
607 public int CompareTo(object val)
612 if (!(val is Decimal))
613 throw new ArgumentException (Locale.GetText ("Value is not a System.Decimal"));
615 Decimal d2 = (Decimal)val;
616 return decimalCompare(ref this, ref d2);
619 public static Decimal Parse(string s)
621 return Parse(s, NumberStyles.Number, null);
624 public static Decimal Parse(string s, NumberStyles style)
626 return Parse(s, style, null);
629 public static Decimal Parse(string s, IFormatProvider provider)
631 return Parse(s, NumberStyles.Number, provider);
634 private static string stripStyles(string s, NumberStyles style, NumberFormatInfo nfi,
635 out int decPos, out bool isNegative, out bool expFlag, out int exp)
637 string invalidChar = Locale.GetText ("Invalid character at position ");
638 string invalidExponent = Locale.GetText ("Invalid exponent");
644 bool hasSign = false;
645 bool hasOpeningParentheses = false;
646 bool hasDecimalPoint = false;
647 bool allowedLeadingWhiteSpace = ((style & NumberStyles.AllowLeadingWhite) != 0);
648 bool allowedTrailingWhiteSpace = ((style & NumberStyles.AllowTrailingWhite) != 0);
649 bool allowedLeadingSign = ((style & NumberStyles.AllowLeadingSign) != 0);
650 bool allowedTrailingSign = ((style & NumberStyles.AllowTrailingSign) != 0);
651 bool allowedParentheses = ((style & NumberStyles.AllowParentheses) != 0);
652 bool allowedThousands = ((style & NumberStyles.AllowThousands) != 0);
653 bool allowedDecimalPoint = ((style & NumberStyles.AllowDecimalPoint) != 0);
654 bool allowedExponent = ((style & NumberStyles.AllowExponent) != 0);
656 /* get rid of currency symbol */
657 bool hasCurrency = false;
658 if ((style & NumberStyles.AllowCurrencySymbol) != 0)
660 int index = s.IndexOf(nfi.CurrencySymbol);
663 s = s.Remove(index, nfi.CurrencySymbol.Length);
668 string decimalSep = (hasCurrency) ? nfi.CurrencyDecimalSeparator : nfi.NumberDecimalSeparator;
669 string groupSep = (hasCurrency) ? nfi.CurrencyGroupSeparator : nfi.NumberGroupSeparator;
674 StringBuilder sb = new StringBuilder(len);
680 if (Char.IsDigit(ch))
682 break; // end of leading
684 else if (allowedLeadingWhiteSpace && Char.IsWhiteSpace(ch))
688 else if (allowedParentheses && ch == '(' && !hasSign && !hasOpeningParentheses)
690 hasOpeningParentheses = true;
695 else if (allowedLeadingSign && ch == nfi.NegativeSign[0] && !hasSign)
697 int slen = nfi.NegativeSign.Length;
698 if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos)
705 else if (allowedLeadingSign && ch == nfi.PositiveSign[0] && !hasSign)
707 int slen = nfi.PositiveSign.Length;
708 if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos)
714 else if (allowedDecimalPoint && ch == decimalSep[0])
716 int slen = decimalSep.Length;
717 if (slen != 1 && s.IndexOf(decimalSep, pos, slen) != pos)
719 throw new FormatException(invalidChar + pos);
725 throw new FormatException(invalidChar + pos);
730 throw new FormatException(Locale.GetText ("No digits found"));
736 if (Char.IsDigit(ch))
741 else if (allowedThousands && ch == groupSep[0])
743 int slen = groupSep.Length;
744 if (slen != 1 && s.IndexOf(groupSep, pos, slen) != pos)
746 throw new FormatException(invalidChar + pos);
750 else if (allowedDecimalPoint && ch == decimalSep[0] && !hasDecimalPoint)
752 int slen = decimalSep.Length;
753 if (slen == 1 || s.IndexOf(decimalSep, pos, slen) == pos)
756 hasDecimalPoint = true;
770 if (allowedExponent && Char.ToUpper(ch) == 'E')
773 pos++; if (pos >= len) throw new FormatException(invalidExponent);
775 bool isNegativeExp = false;
776 if (ch == nfi.PositiveSign[0])
778 int slen = nfi.PositiveSign.Length;
779 if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos)
781 pos += slen; if (pos >= len) throw new FormatException(invalidExponent);
784 else if (ch == nfi.NegativeSign[0])
786 int slen = nfi.NegativeSign.Length;
787 if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos)
789 pos += slen; if (pos >= len) throw new FormatException(invalidExponent);
790 isNegativeExp = true;
794 if (!Char.IsDigit(ch)) throw new FormatException(invalidExponent);
797 while (pos < len && Char.IsDigit(s[pos]))
803 if (isNegativeExp) exp *= -1;
811 if (allowedTrailingWhiteSpace && Char.IsWhiteSpace(ch))
815 else if (allowedParentheses && ch == ')' && hasOpeningParentheses)
817 hasOpeningParentheses = false;
820 else if (allowedTrailingSign && ch == nfi.NegativeSign[0] && !hasSign)
822 int slen = nfi.NegativeSign.Length;
823 if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos)
830 else if (allowedTrailingSign && ch == nfi.PositiveSign[0] && !hasSign)
832 int slen = nfi.PositiveSign.Length;
833 if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos)
841 throw new FormatException(invalidChar + pos);
845 if (hasOpeningParentheses) throw new FormatException (
846 Locale.GetText ("Closing Parentheses not found"));
848 if (!hasDecimalPoint) decPos = sb.Length;
850 return sb.ToString();
853 public static Decimal Parse(string s, NumberStyles style, IFormatProvider provider)
855 NumberFormatInfo nfi = NumberFormatInfo.GetInstance(provider);
857 if (s == null) throw new ArgumentNullException (Locale.GetText ("string s"));
860 bool isNegative, expFlag;
861 s = stripStyles(s, style, nfi, out iDecPos, out isNegative, out expFlag, out exp);
864 throw new Exception (Locale.GetText ("Error in System.Decimal.Parse"));
865 uint decPos = (uint) iDecPos;
868 int digits = s.Length;
869 int sign = (isNegative) ? 1 : 0;
870 if (string2decimal(out d, s, decPos, sign) != 0)
872 throw new OverflowException();
877 if (decimalSetExponent(ref d, exp) != 0)
878 throw new OverflowException();
884 public TypeCode GetTypeCode ()
886 return TypeCode.Decimal;
889 public static byte ToByte (decimal value)
891 return Convert.ToByte (value);
894 public static double ToDouble (decimal value)
896 return Convert.ToDouble (value);
899 public static short ToInt16 (decimal value)
901 return Convert.ToInt16 (value);
904 public static int ToInt32 (decimal value)
906 return Convert.ToInt32 (value);
909 public static long ToInt64 (decimal value)
911 return Convert.ToInt64 (value);
914 public static long ToOACurrency (decimal value)
916 return (long) (value * 10000);
919 [CLSCompliant(false)]
920 public static sbyte ToSByte (decimal value)
922 return Convert.ToSByte (value);
925 public static float ToSingle (decimal value)
927 return Convert.ToSingle (value);
930 [CLSCompliant(false)]
931 public static ushort ToUInt16 (decimal value)
933 return Convert.ToUInt16 (value);
936 [CLSCompliant(false)]
937 public static uint ToUInt32 (decimal value)
939 return Convert.ToUInt32 (value);
942 [CLSCompliant(false)]
943 public static ulong ToUInt64 (decimal value)
945 return Convert.ToUInt64 (value);
948 object IConvertible.ToType (Type conversionType, IFormatProvider provider)
950 return Convert.ToType (this, conversionType, provider);
953 bool IConvertible.ToBoolean (IFormatProvider provider)
955 return Convert.ToBoolean (this);
958 byte IConvertible.ToByte (IFormatProvider provider)
960 return Convert.ToByte (this);
963 char IConvertible.ToChar (IFormatProvider provider)
965 throw new InvalidCastException ();
968 [CLSCompliant (false)]
969 DateTime IConvertible.ToDateTime (IFormatProvider provider)
971 throw new InvalidCastException ();
974 decimal IConvertible.ToDecimal (IFormatProvider provider)
979 double IConvertible.ToDouble (IFormatProvider provider)
981 return Convert.ToDouble (this);
984 short IConvertible.ToInt16 (IFormatProvider provider)
986 return Convert.ToInt16 (this);
989 int IConvertible.ToInt32 (IFormatProvider provider)
991 return Convert.ToInt32 (this);
994 long IConvertible.ToInt64 (IFormatProvider provider)
996 return Convert.ToInt64 (this);
999 [CLSCompliant (false)]
1000 sbyte IConvertible.ToSByte (IFormatProvider provider)
1002 return Convert.ToSByte (this);
1005 float IConvertible.ToSingle (IFormatProvider provider)
1007 return Convert.ToSingle (this);
1010 [CLSCompliant (false)]
1011 ushort IConvertible.ToUInt16 (IFormatProvider provider)
1013 return Convert.ToUInt16 (this);
1016 [CLSCompliant (false)]
1017 uint IConvertible.ToUInt32 (IFormatProvider provider)
1019 return Convert.ToUInt32 (this);
1022 [CLSCompliant (false)]
1023 ulong IConvertible.ToUInt64 (IFormatProvider provider)
1025 return Convert.ToUInt64 (this);
1028 public string ToString(string format, IFormatProvider provider)
1030 NumberFormatInfo nfi = NumberFormatInfo.GetInstance(provider);
1032 if (format == null) format = "G";
1034 return DecimalFormatter.NumberToString(format, nfi, this);
1037 public override string ToString()
1039 return ToString("G", null);
1042 public string ToString(string format)
1044 return ToString(format, null);
1047 public string ToString(IFormatProvider provider)
1049 return ToString("G", provider);
1053 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1054 private static extern int decimal2UInt64(ref Decimal val,
1057 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1058 private static extern int decimal2Int64(ref Decimal val,
1061 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1062 private static extern int double2decimal(out Decimal erg,
1063 double val, int digits);
1065 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1066 private static extern int decimalIncr(ref Decimal d1, ref Decimal d2);
1068 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1069 internal static extern int decimal2string(ref Decimal val,
1070 int digits, int decimals, char[] bufDigits, int bufSize, out int decPos, out int sign);
1072 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1073 internal static extern int string2decimal(out Decimal val, String sDigits, uint decPos, int sign);
1075 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1076 internal static extern int decimalSetExponent(ref Decimal val, int exp);
1078 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1079 private static extern double decimal2double(ref Decimal val);
1081 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1082 private static extern void decimalFloorAndTrunc(ref Decimal val,
1085 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1086 private static extern void decimalRound(ref Decimal val, int decimals);
1088 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1089 private static extern int decimalMult(ref Decimal pd1, ref Decimal pd2);
1091 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1092 private static extern int decimalDiv(out Decimal pc, ref Decimal pa, ref Decimal pb);
1094 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1095 private static extern int decimalIntDiv(out Decimal pc, ref Decimal pa, ref Decimal pb);
1097 [MethodImplAttribute(MethodImplOptions.InternalCall)]
1098 private static extern int decimalCompare(ref Decimal d1, ref Decimal d2);
1100 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1101 [DllImport("libdec", EntryPoint="decimal2UInt64")]
1102 private static extern int decimal2UInt64(ref Decimal val,
1105 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1106 [DllImport("libdec", EntryPoint="decimal2Int64")]
1107 private static extern int decimal2Int64(ref Decimal val,
1110 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1111 [DllImport("libdec", EntryPoint="double2decimal")]
1112 private static extern int double2decimal(out Decimal erg,
1113 double val, int digits);
1115 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1116 [DllImport("libdec", EntryPoint="decimalIncr")]
1117 private static extern int decimalIncr(ref Decimal d1, ref Decimal d2);
1119 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1120 [DllImport("libdec", EntryPoint="decimal2string")]
1121 internal static extern int decimal2string(ref Decimal val,
1122 int digits, int decimals,
1123 [MarshalAs(UnmanagedType.LPWStr)]StringBuilder bufDigits,
1124 int bufSize, out int decPos, out int sign);
1126 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1127 [DllImport("libdec", EntryPoint="string2decimal")]
1128 internal static extern int string2decimal(out Decimal val,
1129 [MarshalAs(UnmanagedType.LPWStr)]String sDigits,
1130 uint decPos, int sign);
1132 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1133 [DllImport("libdec", EntryPoint="decimalSetExponent")]
1134 internal static extern int decimalSetExponent(ref Decimal val, int exp);
1136 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1137 [DllImport("libdec", EntryPoint="decimal2double")]
1138 private static extern double decimal2double(ref Decimal val);
1140 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1141 [DllImport("libdec", EntryPoint="decimalFloorAndTrunc")]
1142 private static extern void decimalFloorAndTrunc(ref Decimal val,
1145 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1146 [DllImport("libdec", EntryPoint="decimalRound")]
1147 private static extern void decimalRound(ref Decimal val, int decimals);
1149 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1150 [DllImport("libdec", EntryPoint="decimalMult")]
1151 private static extern int decimalMult(ref Decimal pd1, ref Decimal pd2);
1153 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1154 [DllImport("libdec", EntryPoint="decimalDiv")]
1155 private static extern int decimalDiv(out Decimal pc, ref Decimal pa, ref Decimal pb);
1157 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1158 [DllImport("libdec", EntryPoint="decimalIntDiv")]
1159 private static extern int decimalIntDiv(out Decimal pc, ref Decimal pa, ref Decimal pb);
1161 //![MethodImplAttribute(MethodImplOptions.InternalCall)]
1162 [DllImport("libdec", EntryPoint="decimalCompare")]
1163 private static extern int decimalCompare(ref Decimal d1, ref Decimal d2);