2010-02-09 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / Test / System / DecimalTest.cs
1 // DecimalTest.cs - NUnit Test Cases for the System.Decimal struct
2 //
3 // Authors:
4 //      Martin Weindel (martin.weindel@t-online.de)
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) Martin Weindel, 2001
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 // 
10
11 using NUnit.Framework;
12 using System;
13
14 using System.Globalization;
15 using System.Runtime.CompilerServices;
16 using System.Threading;
17
18 namespace MonoTests.System
19 {
20         internal struct ParseTest
21         {
22                 public ParseTest (String str, bool exceptionFlag)
23                 {
24                         this.str = str;
25                         this.exceptionFlag = exceptionFlag;
26                         this.style = NumberStyles.Number;
27                         this.d = 0;
28                 }
29
30                 public ParseTest (String str, Decimal d)
31                 {
32                         this.str = str;
33                         this.exceptionFlag = false;
34                         this.style = NumberStyles.Number;
35                         this.d = d;
36                 }
37
38                 public ParseTest (String str, Decimal d, NumberStyles style)
39                 {
40                         this.str = str;
41                         this.exceptionFlag = false;
42                         this.style = style;
43                         this.d = d;
44                 }
45
46                 public String str;
47                 public Decimal d;
48                 public NumberStyles style;
49                 public bool exceptionFlag;
50         }
51
52         internal struct ToStringTest
53         {
54                 public ToStringTest (String format, Decimal d, String str)
55                 {
56                         this.format = format;
57                         this.d = d;
58                         this.str = str;
59                 }
60
61                 public String format;
62                 public Decimal d;
63                 public String str;
64         }
65
66         [TestFixture]
67         public class DecimalTest
68         {
69                 private const int negativeBitValue = unchecked ((int) 0x80000000);
70                 private const int negativeScale4Value = unchecked ((int) 0x80040000);
71                 private int [] parts0 = { 0, 0, 0, 0 }; //Positive Zero.
72                 private int [] parts1 = { 1, 0, 0, 0 };
73                 private int [] parts2 = { 0, 1, 0, 0 };
74                 private int [] parts3 = { 0, 0, 1, 0 };
75                 private int [] parts4 = { 0, 0, 0, negativeBitValue }; // Negative zero.
76                 private int [] parts5 = { 1, 1, 1, 0 };
77                 private int [] partsMaxValue = { -1, -1, -1, 0 };
78                 private int [] partsMinValue = { -1, -1, -1, negativeBitValue };
79                 private int [] parts6 = { 1234, 5678, 8888, negativeScale4Value };
80                 private NumberFormatInfo NfiUser, NfiBroken;
81
82                 private CultureInfo old_culture;
83
84                 [TestFixtureSetUp]
85                 public void FixtureSetUp ()
86                 {
87                         old_culture = Thread.CurrentThread.CurrentCulture;
88
89                         // Set culture to en-US and don't let the user override.
90                         Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US", false);
91
92                         NfiUser = new NumberFormatInfo ();
93                         NfiUser.CurrencyDecimalDigits = 3;
94                         NfiUser.CurrencyDecimalSeparator = ",";
95                         NfiUser.CurrencyGroupSeparator = "_";
96                         NfiUser.CurrencyGroupSizes = new int [] { 2, 1, 0 };
97                         NfiUser.CurrencyNegativePattern = 10;
98                         NfiUser.CurrencyPositivePattern = 3;
99                         NfiUser.CurrencySymbol = "XYZ";
100                         NfiUser.NumberDecimalSeparator = "##";
101                         NfiUser.NumberDecimalDigits = 4;
102                         NfiUser.NumberGroupSeparator = "__";
103                         NfiUser.NumberGroupSizes = new int [] { 2, 1 };
104                         NfiUser.PercentDecimalDigits = 1;
105                         NfiUser.PercentDecimalSeparator = ";";
106                         NfiUser.PercentGroupSeparator = "~";
107                         NfiUser.PercentGroupSizes = new int [] { 1 };
108                         NfiUser.PercentNegativePattern = 2;
109                         NfiUser.PercentPositivePattern = 2;
110                         NfiUser.PercentSymbol = "%%%";
111
112                         NfiBroken = new NumberFormatInfo ();
113                         NfiBroken.NumberDecimalSeparator = ".";
114                         NfiBroken.NumberGroupSeparator = ".";
115                         NfiBroken.CurrencyDecimalSeparator = ".";
116                         NfiBroken.CurrencyGroupSeparator = ".";
117                 }
118
119                 [TestFixtureTearDown]
120                 public void FixtureTearDown ()
121                 {
122                         Thread.CurrentThread.CurrentCulture = old_culture;
123                 }
124
125                 [Test]
126                 public void TestToString ()
127                 {
128                         ToStringTest [] tab = {
129                                 new ToStringTest ("F", 12.345678m, "12.35"),
130                                 new ToStringTest ("F3", 12.345678m, "12.346"),
131                                 new ToStringTest ("F0", 12.345678m, "12"),
132                                 new ToStringTest ("F7", 12.345678m, "12.3456780"),
133                                 new ToStringTest ("g", 12.345678m, "12.345678"),
134                                 new ToStringTest ("E", 12.345678m, "1.234568E+001"),
135                                 new ToStringTest ("E3", 12.345678m, "1.235E+001"),
136                                 new ToStringTest ("E0", 12.345678m, "1E+001"),
137                                 new ToStringTest ("e8", 12.345678m, "1.23456780e+001"),
138                                 new ToStringTest ("F", 0.0012m, "0.00"),
139                                 new ToStringTest ("F3", 0.0012m, "0.001"),
140                                 new ToStringTest ("F0", 0.0012m, "0"),
141                                 new ToStringTest ("F6", 0.0012m, "0.001200"),
142                                 new ToStringTest ("e", 0.0012m, "1.200000e-003"),
143                                 new ToStringTest ("E3", 0.0012m, "1.200E-003"),
144                                 new ToStringTest ("E0", 0.0012m, "1E-003"),
145                                 new ToStringTest ("E6", 0.0012m, "1.200000E-003"),
146                                 new ToStringTest ("F4", -0.001234m, "-0.0012"),
147                                 new ToStringTest ("E3", -0.001234m, "-1.234E-003"),
148                                 new ToStringTest ("g", -0.000012m, "-0.000012"),
149                                 new ToStringTest ("g0", -0.000012m, "-1.2e-05"),
150                                 new ToStringTest ("g2", -0.000012m, "-1.2e-05"),
151                                 new ToStringTest ("g20", -0.000012m, "-1.2e-05"),
152                                 new ToStringTest ("g", -0.00012m, "-0.00012"),
153                                 new ToStringTest ("g4", -0.00012m, "-0.00012"),
154                                 new ToStringTest ("g7", -0.00012m, "-0.00012"),
155                                 new ToStringTest ("g", -0.0001234m, "-0.0001234"),
156                                 new ToStringTest ("g", -0.0012m, "-0.0012"),
157                                 new ToStringTest ("g", -0.001234m, "-0.001234"),
158                                 new ToStringTest ("g", -0.012m, "-0.012"),
159                                 new ToStringTest ("g4", -0.012m, "-0.012"),
160                                 new ToStringTest ("g", -0.12m, "-0.12"),
161                                 new ToStringTest ("g", -1.2m, "-1.2"),
162                                 new ToStringTest ("g4", -120m, "-120"),
163                                 new ToStringTest ("g", -12.000m, "-12.000"),
164                                 new ToStringTest ("g0", -12.000m, "-12"),
165                                 new ToStringTest ("g6", -12.000m, "-12"),
166                                 new ToStringTest ("g", -12m, "-12"),
167                                 new ToStringTest ("g", -120m, "-120"),
168                                 new ToStringTest ("g", -1200m, "-1200"),
169                                 new ToStringTest ("g4", -1200m, "-1200"),
170                                 new ToStringTest ("g", -1234m, "-1234"),
171                                 new ToStringTest ("g", -12000m, "-12000"),
172                                 new ToStringTest ("g4", -12000m, "-1.2e+04"),
173                                 new ToStringTest ("g5", -12000m, "-12000"),
174                                 new ToStringTest ("g", -12345m, "-12345"),
175                                 new ToStringTest ("g", -120000m, "-120000"),
176                                 new ToStringTest ("g4", -120000m, "-1.2e+05"),
177                                 new ToStringTest ("g5", -120000m, "-1.2e+05"),
178                                 new ToStringTest ("g6", -120000m, "-120000"),
179                                 new ToStringTest ("g", -123456.1m, "-123456.1"),
180                                 new ToStringTest ("g5", -123456.1m, "-1.2346e+05"),
181                                 new ToStringTest ("g6", -123456.1m, "-123456"),
182                                 new ToStringTest ("g", -1200000m, "-1200000"),
183                                 new ToStringTest ("g", -123456.1m, "-123456.1"),
184                                 new ToStringTest ("g", -123456.1m, "-123456.1"),
185                                 new ToStringTest ("g", -1234567.1m, "-1234567.1"),
186                                 new ToStringTest ("g", -12000000m, "-12000000"),
187                                 new ToStringTest ("g", -12345678.1m, "-12345678.1"),
188                                 new ToStringTest ("g", -12000000000000000000m, "-12000000000000000000"),
189                                 new ToStringTest ("F", -123, "-123.00"),
190                                 new ToStringTest ("F3", -123, "-123.000"),
191                                 new ToStringTest ("F0", -123, "-123"),
192                                 new ToStringTest ("E3", -123, "-1.230E+002"),
193                                 new ToStringTest ("E0", -123, "-1E+002"),
194                                 new ToStringTest ("E", -123, "-1.230000E+002"),
195                                 new ToStringTest ("F3", Decimal.MinValue, "-79228162514264337593543950335.000"),
196                                 new ToStringTest ("F", Decimal.MinValue, "-79228162514264337593543950335.00"),
197                                 new ToStringTest ("F0", Decimal.MinValue, "-79228162514264337593543950335"),
198                                 new ToStringTest ("E", Decimal.MinValue, "-7.922816E+028"),
199                                 new ToStringTest ("E3", Decimal.MinValue, "-7.923E+028"),
200                                 new ToStringTest ("E28", Decimal.MinValue, "-7.9228162514264337593543950335E+028"),
201 #if !TARGET_JVM // TargetJvmNotWorking
202                                 new ToStringTest ("E30", Decimal.MinValue, "-7.922816251426433759354395033500E+028"),
203 #endif
204                                 new ToStringTest ("E0", Decimal.MinValue, "-8E+028"),
205                                 new ToStringTest ("N3", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335.000"),
206                                 new ToStringTest ("N0", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335"),
207                                 new ToStringTest ("N", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335.00"),
208                                 new ToStringTest ("n3", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335.000"),
209                                 new ToStringTest ("n0", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335"),
210                                 new ToStringTest ("n", Decimal.MinValue, "-79,228,162,514,264,337,593,543,950,335.00"),
211                                 new ToStringTest ("C", 123456.7890m, NumberFormatInfo.InvariantInfo.CurrencySymbol + "123,456.79"),
212                                 new ToStringTest ("C", -123456.7890m, "(" + NumberFormatInfo.InvariantInfo.CurrencySymbol + "123,456.79)"),
213                                 new ToStringTest ("C3", 1123456.7890m, NumberFormatInfo.InvariantInfo.CurrencySymbol + "1,123,456.789"),
214                                 new ToStringTest ("P", 123456.7891m, "12,345,678.91 %"),
215                                 new ToStringTest ("P", -123456.7892m, "-12,345,678.92 %"),
216                                 new ToStringTest ("P3", 1234.56789m, "123,456.789 %"),
217                         };
218
219                         NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
220
221                         for (int i = 0; i < tab.Length; i++) {
222                                 try {
223                                         string s = tab [i].d.ToString (tab [i].format, nfi);
224                                         Assert.AreEqual (tab [i].str, s, "A01 tab[" + i + "].format = '" + tab [i].format + "')");
225                                 } catch (OverflowException) {
226                                         Assert.Fail (tab [i].d.ToString (tab [i].format, nfi) + " (format = '" + tab [i].format + "'): unexpected exception !");
227                                 } catch (NUnit.Framework.AssertionException e) {
228                                         throw e;
229                                 } catch (Exception e) {
230                                         Assert.Fail ("Unexpected Exception when i = " + i + ". e = " + e);
231                                 }
232                         }
233                 }
234
235                 [Test]
236                 public void TestCurrencyPattern ()
237                 {
238                         NumberFormatInfo nfi2 = (NumberFormatInfo) NfiUser.Clone ();
239                         Decimal d = -1234567.8976m;
240                         string [] ergCurrencyNegativePattern = new String [16] {
241                                 "(XYZ1234_5_67,898)", "-XYZ1234_5_67,898", "XYZ-1234_5_67,898", "XYZ1234_5_67,898-",
242                                 "(1234_5_67,898XYZ)", "-1234_5_67,898XYZ", "1234_5_67,898-XYZ", "1234_5_67,898XYZ-",
243                                 "-1234_5_67,898 XYZ", "-XYZ 1234_5_67,898", "1234_5_67,898 XYZ-", "XYZ 1234_5_67,898-",
244                                 "XYZ -1234_5_67,898", "1234_5_67,898- XYZ", "(XYZ 1234_5_67,898)", "(1234_5_67,898 XYZ)",
245                         };
246
247                         for (int i = 0; i < ergCurrencyNegativePattern.Length; i++) {
248                                 nfi2.CurrencyNegativePattern = i;
249                                 if (d.ToString ("C", nfi2) != ergCurrencyNegativePattern [i]) {
250                                         Assert.Fail ("CurrencyNegativePattern #" + i + " failed: " +
251                                                 d.ToString ("C", nfi2) + " != " + ergCurrencyNegativePattern [i]);
252                                 }
253                         }
254
255                         d = 1234567.8976m;
256                         string [] ergCurrencyPositivePattern = new String [4] {
257                                 "XYZ1234_5_67,898", "1234_5_67,898XYZ", "XYZ 1234_5_67,898", "1234_5_67,898 XYZ",
258                         };
259
260                         for (int i = 0; i < ergCurrencyPositivePattern.Length; i++) {
261                                 nfi2.CurrencyPositivePattern = i;
262                                 if (d.ToString ("C", nfi2) != ergCurrencyPositivePattern [i]) {
263                                         Assert.Fail ("CurrencyPositivePattern #" + i + " failed: " +
264                                                 d.ToString ("C", nfi2) + " != " + ergCurrencyPositivePattern [i]);
265                                 }
266                         }
267                 }
268
269                 [Test]
270                 public void TestNumberNegativePattern ()
271                 {
272                         NumberFormatInfo nfi2 = (NumberFormatInfo) NfiUser.Clone ();
273                         Decimal d = -1234.89765m;
274                         string [] ergNumberNegativePattern = new String [5] {
275                                 "(1__2__34##8977)", "-1__2__34##8977", "- 1__2__34##8977", "1__2__34##8977-", "1__2__34##8977 -",
276                         };
277
278                         for (int i = 0; i < ergNumberNegativePattern.Length; i++) {
279                                 nfi2.NumberNegativePattern = i;
280                                 Assert.AreEqual (ergNumberNegativePattern [i], d.ToString ("N", nfi2), "NumberNegativePattern #" + i);
281                         }
282                 }
283
284                 [Test]
285                 public void TestBrokenNFI ()
286                 {
287                         Assert.AreEqual (5.3m, decimal.Parse ("5.3", NumberStyles.Number, NfiBroken), "Parsing with broken NFI");
288                 }
289                 
290                 [Test]
291                 [Category ("TargetJvmNotWorking")]
292                 public void TestPercentPattern ()
293                 {
294                         NumberFormatInfo nfi2 = (NumberFormatInfo) NfiUser.Clone ();
295                         Decimal d = -1234.8976m;
296                         string [] ergPercentNegativePattern = new String [3] {
297                                 "-1~2~3~4~8~9;8 %%%", "-1~2~3~4~8~9;8%%%", "-%%%1~2~3~4~8~9;8"
298                         };
299
300                         for (int i = 0; i < ergPercentNegativePattern.Length; i++) {
301                                 nfi2.PercentNegativePattern = i;
302                                 if (d.ToString ("P", nfi2) != ergPercentNegativePattern [i]) {
303                                         Assert.Fail ("PercentNegativePattern #" + i + " failed: " +
304                                                 d.ToString ("P", nfi2) + " != " + ergPercentNegativePattern [i]);
305                                 }
306                         }
307
308                         d = 1234.8976m;
309                         string [] ergPercentPositivePattern = new String [3] {
310                                 "1~2~3~4~8~9;8 %%%", "1~2~3~4~8~9;8%%%", "%%%1~2~3~4~8~9;8"
311                         };
312
313                         for (int i = 0; i < ergPercentPositivePattern.Length; i++) {
314                                 nfi2.PercentPositivePattern = i;
315                                 if (d.ToString ("P", nfi2) != ergPercentPositivePattern [i]) {
316                                         Assert.Fail ("PercentPositivePattern #" + i + " failed: " +
317                                                 d.ToString ("P", nfi2) + " != " + ergPercentPositivePattern [i]);
318                                 }
319                         }
320                 }
321
322                 ParseTest [] tab = {
323                                 new ParseTest("1.2345", 1.2345m),
324                                 new ParseTest("1.2345\0", 1.2345m),
325                                 new ParseTest("1.2345\0\0\0\0", 1.2345m),
326                                 new ParseTest("-9876543210", -9876543210m),
327                                 new ParseTest(NumberFormatInfo.InvariantInfo.CurrencySymbol 
328                                         + " (  79,228,162,514,264,337,593,543,950,335.000 ) ", 
329                                         Decimal.MinValue, NumberStyles.Currency),
330                                 new ParseTest("1.234567890e-10", (Decimal)1.234567890e-10, NumberStyles.Float),
331                                 new ParseTest("1.234567890e-24", 1.2346e-24m, NumberStyles.Float),
332                                 new ParseTest("  47896396.457983645462346E10  ", 478963964579836454.62346m, NumberStyles.Float),
333                                 new ParseTest("-7922816251426433759354395033.250000000000001", -7922816251426433759354395033.3m),
334                                 new ParseTest("-00000000000000795033.2500000000000000", -795033.25m),
335                                 new ParseTest("-000000000000001922816251426433759354395033.300000000000000", -1922816251426433759354395033.3m),
336                                 new ParseTest("-7922816251426433759354395033.150000000000", -7922816251426433759354395033.2m),
337                                 new ParseTest("-7922816251426433759354395033.2400000000000", -7922816251426433759354395033.2m),
338                                 new ParseTest("-7922816251426433759354395033.2600000000000", -7922816251426433759354395033.3m)
339                 };
340
341                 [Test]
342                 [Category ("TargetJvmNotWorking")]
343                 public void TestParse ()
344                 {
345
346                         Decimal d;
347                         for (int i = 0; i < tab.Length; i++) {
348                                 try {
349                                         d = Decimal.Parse (tab [i].str, tab [i].style, NumberFormatInfo.InvariantInfo);
350                                         if (tab [i].exceptionFlag) {
351                                                 Assert.Fail (tab [i].str + ": missing exception !");
352                                         } else if (d != tab [i].d) {
353                                                 Assert.Fail (tab [i].str + " != " + d);
354                                         }
355                                 } catch (OverflowException) {
356                                         if (!tab [i].exceptionFlag) {
357                                                 Assert.Fail (tab [i].str + ": unexpected exception !");
358                                         }
359                                 }
360                         }
361
362                         try {
363                                 d = Decimal.Parse (null);
364                                 Assert.Fail ("Expected ArgumentNullException");
365                         } catch (ArgumentNullException) {
366                                 //ok
367                         }
368
369                         try {
370                                 d = Decimal.Parse ("123nx");
371                                 Assert.Fail ("Expected FormatException");
372                         } catch (FormatException) {
373                                 //ok
374                         }
375
376                         try {
377                                 d = Decimal.Parse ("79228162514264337593543950336");
378                                 Assert.Fail ("Expected OverflowException" + d);
379                         } catch (OverflowException) {
380                                 //ok
381                         }
382
383                         try {
384                                 d = Decimal.Parse ("5\05");
385                                 Assert.Fail ("Expected FormatException" + d);
386                         } catch (FormatException) {
387                                 //ok
388                         }
389                 }
390
391                 [Test]
392                 public void TestConstants ()
393                 {
394                         Assert.AreEqual (0m, Decimal.Zero, "Zero");
395                         Assert.AreEqual (1m, Decimal.One, "One");
396                         Assert.AreEqual (-1m, Decimal.MinusOne, "MinusOne");
397                         Assert.AreEqual (79228162514264337593543950335m, Decimal.MaxValue, "MaxValue");
398                         Assert.AreEqual (-79228162514264337593543950335m, Decimal.MinValue, "MinValue");
399                         Assert.IsTrue (-1m == Decimal.MinusOne, "MinusOne 2");
400                 }
401
402                 [Test]
403                 public void TestConstructInt32 ()
404                 {
405                         decimal [] dtab = { 0m, 1m, -1m, 123456m, -1234567m };
406                         int [] itab = { 0, 1, -1, 123456, -1234567 };
407
408                         Decimal d;
409
410                         for (int i = 0; i < dtab.GetLength (0); i++) {
411                                 d = new Decimal (itab [i]);
412                                 if ((decimal) d != dtab [i]) {
413                                         Assert.Fail ("Int32 -> Decimal: " + itab [i] + " != " + d);
414                                 } else {
415                                         int n = (int) d;
416                                         if (n != itab [i]) {
417                                                 Assert.Fail ("Decimal -> Int32: " + d + " != " + itab [i]);
418                                         }
419                                 }
420                         }
421
422                         d = new Decimal (Int32.MaxValue);
423                         Assert.IsTrue ((int) d == Int32.MaxValue);
424
425                         d = new Decimal (Int32.MinValue);
426                         Assert.IsTrue ((int) d == Int32.MinValue);
427                 }
428
429                 [Test]
430                 public void TestConstructUInt32 ()
431                 {
432                         decimal [] dtab = { 0m, 1m, 123456m, 123456789m };
433                         uint [] itab = { 0, 1, 123456, 123456789 };
434
435                         Decimal d;
436
437                         for (int i = 0; i < dtab.GetLength (0); i++) {
438                                 d = new Decimal (itab [i]);
439                                 if ((decimal) d != dtab [i]) {
440                                         Assert.Fail ("UInt32 -> Decimal: " + itab [i] + " != " + d);
441                                 } else {
442                                         uint n = (uint) d;
443                                         if (n != itab [i]) {
444                                                 Assert.Fail ("Decimal -> UInt32: " + d + " != " + itab [i]);
445                                         }
446                                 }
447                         }
448
449                         d = new Decimal (UInt32.MaxValue);
450                         Assert.IsTrue ((uint) d == UInt32.MaxValue);
451
452                         d = new Decimal (UInt32.MinValue);
453                         Assert.IsTrue ((uint) d == UInt32.MinValue);
454                 }
455
456                 [Test]
457                 public void TestConstructInt64 ()
458                 {
459                         decimal [] dtab = { 0m, 1m, -1m, 9876543m, -9876543210m, 12345678987654321m };
460                         long [] itab = { 0, 1, -1, 9876543, -9876543210L, 12345678987654321L };
461
462                         Decimal d;
463
464                         for (int i = 0; i < dtab.GetLength (0); i++) {
465                                 d = new Decimal (itab [i]);
466                                 if ((decimal) d != dtab [i]) {
467                                         Assert.Fail ("Int64 -> Decimal: " + itab [i] + " != " + d);
468                                 } else {
469                                         long n = (long) d;
470                                         if (n != itab [i]) {
471                                                 Assert.Fail ("Decimal -> Int64: " + d + " != " + itab [i]);
472                                         }
473                                 }
474                         }
475
476                         d = new Decimal (Int64.MaxValue);
477                         Assert.IsTrue ((long) d == Int64.MaxValue);
478
479                         d = new Decimal (Int64.MinValue);
480                         Assert.IsTrue ((long) d == Int64.MinValue);
481                 }
482
483                 [Test]
484                 public void TestConstructUInt64 ()
485                 {
486                         decimal [] dtab = { 0m, 1m, 987654321m, 123456789876543210m };
487                         ulong [] itab = { 0, 1, 987654321, 123456789876543210L };
488
489                         Decimal d;
490
491                         for (int i = 0; i < dtab.GetLength (0); i++) {
492                                 d = new Decimal (itab [i]);
493                                 if ((decimal) d != dtab [i]) {
494                                         Assert.Fail ("UInt64 -> Decimal: " + itab [i] + " != " + d);
495                                 } else {
496                                         ulong n = (ulong) d;
497                                         if (n != itab [i]) {
498                                                 Assert.Fail ("Decimal -> UInt64: " + d + " != " + itab [i]);
499                                         }
500                                 }
501                         }
502
503                         d = new Decimal (UInt64.MaxValue);
504                         Assert.IsTrue ((ulong) d == UInt64.MaxValue);
505
506                         d = new Decimal (UInt64.MinValue);
507                         Assert.IsTrue ((ulong) d == UInt64.MinValue);
508                 }
509
510                 [Test]
511                 public void TestConstructSingle ()
512                 {
513                         Decimal d;
514
515                         d = new Decimal (-1.2345678f);
516                         Assert.AreEqual (-1.234568m, (decimal) d, "A#01");
517
518                         d = 3;
519                         Assert.AreEqual (3.0f, (float) d, "A#02");
520
521                         d = new Decimal (0.0f);
522                         Assert.AreEqual (0m, (decimal) d, "A#03");
523                         Assert.AreEqual (0.0f, (float) d, "A#04");
524
525                         d = new Decimal (1.0f);
526                         Assert.AreEqual (1m, (decimal) d, "A#05");
527                         Assert.AreEqual (1.0f, (float) d, "A#06");
528
529                         d = new Decimal (-1.2345678f);
530                         Assert.AreEqual (-1.234568m, (decimal) d, "A#07");
531                         Assert.AreEqual (-1.234568f, (float) d, "A#08");
532
533                         d = new Decimal (1.2345673f);
534                         Assert.AreEqual (1.234567m, (decimal) d, "A#09");
535
536                         d = new Decimal (1.2345673e7f);
537                         Assert.AreEqual (12345670m, (decimal) d, "A#10");
538
539                         d = new Decimal (1.2345673e-17f);
540                         Assert.AreEqual (0.00000000000000001234567m, (decimal) d, "A#11");
541                         Assert.AreEqual (1.234567e-17f, (float) d, "A#12");
542
543                         // test exceptions
544                         try {
545                                 d = new Decimal (Single.MaxValue);
546                                 Assert.Fail ();
547                         } catch (OverflowException) {
548                         }
549
550                         try {
551                                 d = new Decimal (Single.NaN);
552                                 Assert.Fail ();
553                         } catch (OverflowException) {
554                         }
555
556                         try {
557                                 d = new Decimal (Single.PositiveInfinity);
558                                 Assert.Fail ();
559                         } catch (OverflowException) {
560                         }
561                 }
562
563                 [Test]
564                 public void TestConstructSingleRounding_NowWorking ()
565                 {
566                         decimal d;
567
568                         d = new Decimal (1765.23454f);
569                         Assert.AreEqual (1765.234m, d, "failed banker's rule rounding test 2");
570
571                         d = new Decimal (0.00017652356f);
572                         Assert.AreEqual (0.0001765236m, d, "06");
573
574                         d = new Decimal (0.000176523554f);
575                         Assert.AreEqual (0.0001765236m, d, "failed banker's rule rounding test 3");
576
577                         d = new Decimal (0.00017652354f);
578                         Assert.AreEqual (0.0001765235m, d, "08");
579
580                         d = new Decimal (0.00017652346f);
581                         Assert.AreEqual (0.0001765235m, d, "09");
582
583                         d = new Decimal (0.000176523454f);
584                         Assert.AreEqual (0.0001765234m, d, "failed banker's rule rounding test 4");
585
586                         d = new Decimal (0.00017652344f);
587                         Assert.AreEqual (0.0001765234m, d, "11");
588                 }
589
590                 public void TestConstructSingleRounding ()
591                 {
592                         decimal d;
593
594                         d = new Decimal (1765.2356f);
595                         Assert.IsTrue (d == 1765.236m, "01");
596
597                         d = new Decimal (1765.23554f);
598                         Assert.IsTrue (d == 1765.236m, "failed banker's rule rounding test 1");
599
600                         d = new Decimal (1765.2354f);
601                         Assert.IsTrue (d == 1765.235m, "03");
602
603                         d = new Decimal (1765.2346f);
604                         Assert.IsTrue (d == 1765.235m, "04");
605
606                         d = new Decimal (1765.2344f);
607                         Assert.IsTrue (d == 1765.234m, "05");
608
609                         d = new Decimal (3.7652356e10f);
610                         Assert.IsTrue (d == 37652360000m, "12");
611
612                         d = new Decimal (3.7652356e20f);
613                         Assert.IsTrue (d == 376523600000000000000m, "13");
614
615                         d = new Decimal (3.76523554e20f);
616                         Assert.IsTrue (d == 376523600000000000000m, "failed banker's rule rounding test 5");
617
618                         d = new Decimal (3.7652352e20f);
619                         Assert.IsTrue (d == 376523500000000000000m, "15");
620
621                         d = new Decimal (3.7652348e20f);
622                         Assert.IsTrue (d == 376523500000000000000m, "16");
623
624                         d = new Decimal (3.76523454e20f);
625                         Assert.IsTrue (d == 376523400000000000000m, "failed banker's rule rounding test 6");
626
627                         d = new Decimal (3.7652342e20f);
628                         Assert.IsTrue (d == 376523400000000000000m, "18");
629                 }
630
631                 [Test]
632                 public void TestConstructDouble ()
633                 {
634                         Decimal d;
635
636                         d = new Decimal (0.0);
637                         Assert.IsTrue ((decimal) d == 0m);
638
639                         d = new Decimal (1.0);
640                         Assert.IsTrue ((decimal) d == 1m);
641                         Assert.IsTrue (1.0 == (double) d);
642
643                         d = new Decimal (-1.2345678901234);
644                         Assert.IsTrue ((decimal) d == -1.2345678901234m);
645                         Assert.IsTrue (-1.2345678901234 == (double) d);
646
647                         d = new Decimal (1.2345678901234);
648                         Assert.IsTrue ((decimal) d == 1.2345678901234m);
649
650                         d = new Decimal (1.2345678901234e8);
651                         Assert.IsTrue ((decimal) d == 123456789.01234m);
652                         Assert.IsTrue (1.2345678901234e8 == (double) d);
653
654                         d = new Decimal (1.2345678901234e16);
655                         Assert.IsTrue ((decimal) d == 12345678901234000m);
656                         Assert.IsTrue (1.2345678901234e16 == (double) d);
657
658                         d = new Decimal (1.2345678901234e24);
659                         Assert.IsTrue ((decimal) d == 1234567890123400000000000m);
660                         Assert.IsTrue (1.2345678901234e24 == (double) d);
661
662                         d = new Decimal (1.2345678901234e28);
663                         Assert.IsTrue ((decimal) d == 1.2345678901234e28m);
664                         Assert.IsTrue (1.2345678901234e28 == (double) d);
665
666                         d = new Decimal (7.2345678901234e28);
667                         Assert.IsTrue ((decimal) d == 7.2345678901234e28m);
668                         Assert.IsTrue (new Decimal ((double) d) == d);
669
670                         d = new Decimal (1.2345678901234e-8);
671                         Assert.IsTrue ((decimal) d == 1.2345678901234e-8m);
672
673                         d = new Decimal (1.2345678901234e-14);
674                         Assert.IsTrue ((decimal) d == 1.2345678901234e-14m);
675                         Assert.IsTrue (1.2345678901234e-14 == (double) d);
676
677                         d = new Decimal (1.2342278901234e-25);
678                         Assert.AreEqual (d, 1.234e-25m, "A10");
679
680                         // test exceptions
681                         try {
682                                 d = new Decimal (8e28);
683                                 Assert.Fail ();
684                         } catch (OverflowException) {
685                         }
686
687                         try {
688                                 d = new Decimal (8e48);
689                                 Assert.Fail ();
690                         } catch (OverflowException) {
691                         }
692
693                         try {
694                                 d = new Decimal (Double.NaN);
695                                 Assert.Fail ();
696                         } catch (OverflowException) {
697                         }
698
699                         try {
700                                 d = new Decimal (Double.PositiveInfinity);
701                                 Assert.Fail ();
702                         } catch (OverflowException) {
703                         }
704                 }
705
706                 [Test]
707                 public void TestConstructDoubleRound ()
708                 {
709                         decimal d;
710                         int TestNum = 1;
711
712                         try {
713                                 d = new Decimal (1765.231234567857);
714                                 Assert.AreEqual (1765.23123456786m, d, "A01");
715
716                                 TestNum++;
717                                 d = new Decimal (1765.2312345678554);
718                                 Assert.AreEqual (1765.23123456786m, d, "A02, failed banker's rule rounding test 1");
719                                 Assert.AreEqual (1765.23123456786, (double) d, "A03");
720
721                                 TestNum++;
722                                 d = new Decimal (1765.231234567853);
723                                 Assert.IsTrue (d == 1765.23123456785m);
724
725                                 TestNum++;
726                                 d = new Decimal (1765.231234567847);
727                                 Assert.IsTrue (d == 1765.23123456785m);
728
729                                 TestNum++;
730                                 d = new Decimal (1765.231234567843);
731                                 Assert.IsTrue (d == 1765.23123456784m);
732
733                                 TestNum++;
734                                 d = new Decimal (1.765231234567857e-9);
735                                 Assert.IsTrue (d == 1.76523123456786e-9m);
736
737                                 TestNum++;
738                                 d = new Decimal (1.7652312345678554e-9);
739                                 Assert.IsTrue (d == 1.76523123456786e-9m, "failed banker's rule rounding test 3");
740
741                                 TestNum++;
742                                 d = new Decimal (1.765231234567853e-9);
743                                 Assert.IsTrue (d == 1.76523123456785e-9m);
744
745                                 TestNum++;
746                                 d = new Decimal (1.765231234567857e+24);
747                                 Assert.IsTrue (d == 1.76523123456786e+24m);
748
749                                 TestNum++;
750                                 d = new Decimal (1.7652312345678554e+24);
751                                 Assert.IsTrue (d == 1.76523123456786e+24m, "failed banker's rule rounding test 4");
752
753                                 TestNum++;
754                                 d = new Decimal (1.765231234567853e+24);
755                                 Assert.IsTrue (d == 1.76523123456785e+24m);
756
757                                 TestNum++;
758                                 d = new Decimal (1765.2312345678454);
759                                 Assert.IsTrue (d == 1765.23123456785m);
760                         } catch (Exception e) {
761                                 Assert.Fail ("At TestNum = " + TestNum + " unexpected exception. e = " + e);
762                         }
763                 }
764
765                 [Test]
766                 public void TestNegate ()
767                 {
768                         decimal d;
769
770                         d = new Decimal (12345678);
771                         Assert.IsTrue ((decimal) Decimal.Negate (d) == -12345678m);
772                 }
773
774                 [Test]
775                 public void TestPartConstruct ()
776                 {
777                         decimal d;
778
779                         d = new Decimal (parts0);
780                         Assert.IsTrue (d == 0);
781
782                         d = new Decimal (parts1);
783                         Assert.IsTrue (d == 1);
784
785                         d = new Decimal (parts2);
786                         Assert.IsTrue (d == 4294967296m);
787
788                         d = new Decimal (parts3);
789                         Assert.IsTrue (d == 18446744073709551616m);
790
791                         d = new Decimal (parts4);
792                         Assert.IsTrue (d == 0m);
793
794                         d = new Decimal (parts5);
795                         Assert.IsTrue (d == 18446744078004518913m);
796
797                         d = new Decimal (partsMaxValue);
798                         Assert.IsTrue (d == Decimal.MaxValue);
799
800                         d = new Decimal (partsMinValue);
801                         Assert.IsTrue (d == Decimal.MinValue);
802
803                         d = new Decimal (parts6);
804                         int [] erg = Decimal.GetBits (d);
805                         for (int i = 0; i < 4; i++) {
806                                 Assert.IsTrue (erg [i] == parts6 [i]);
807                         }
808                 }
809
810                 [Test]
811                 public void TestFloorTruncate ()
812                 {
813                         decimal [,] dtab = {
814                                 {0m, 0m, 0m}, {1m, 1m, 1m}, {-1m, -1m, -1m}, {1.1m, 1m, 1m}, 
815                                 {-1.000000000001m, -2m, -1m}, {12345.67890m,12345m,12345m},
816                                 {-123456789012345.67890m, -123456789012346m, -123456789012345m},
817                                 {Decimal.MaxValue, Decimal.MaxValue, Decimal.MaxValue},
818                                 {Decimal.MinValue, Decimal.MinValue, Decimal.MinValue},
819                                 {6.999999999m, 6m, 6m}, {-6.999999999m, -7m, -6m}, 
820                                 {0.00001m, 0m, 0m}, {-0.00001m, -1m, 0m}
821                         };
822
823                         decimal d;
824
825                         for (int i = 0; i < dtab.GetLength (0); i++) {
826                                 d = Decimal.Floor (dtab [i, 0]);
827                                 if (d != dtab [i, 1]) {
828                                         Assert.Fail ("Floor: Floor(" + dtab [i, 0] + ") != " + d);
829                                 }
830                                 d = Decimal.Truncate (dtab [i, 0]);
831                                 if (d != dtab [i, 2]) {
832                                         Assert.Fail ("Truncate: Truncate(" + dtab [i, 0] + ") != " + d);
833                                 }
834                         }
835                 }
836
837                 [Test]
838                 public void Truncate ()
839                 {
840                         decimal dd = 249.9m;
841                         decimal dt = Decimal.Truncate (dd);
842                         Assert.AreEqual (249.9m, dd, "Original");
843                         Assert.AreEqual (249m, dt, "Truncate");
844                         Assert.AreEqual (249, (byte) dd, "Cast-Byte");
845                         Assert.AreEqual (249, (char) dd, "Cast-Char");
846                         Assert.AreEqual (249, (short) dd, "Cast-Int16");
847                         Assert.AreEqual (249, (ushort) dd, "Cast-UInt16");
848                         Assert.AreEqual (249, (int) dd, "Cast-Int32");
849                         Assert.AreEqual (249, (uint) dd, "Cast-UInt32");
850                         Assert.AreEqual (249, (long) dd, "Cast-Int64");
851                         Assert.AreEqual (249, (ulong) dd, "Cast-UInt64");
852                 }
853
854                 [Test]
855                 public void TestRound ()
856                 {
857                         decimal [,] dtab = { 
858                                 {1m, 0, 1m}, {1.234567890m, 1, 1.2m}, 
859                                 {1.234567890m, 2, 1.23m}, {1.23450000001m, 3, 1.235m}, 
860                                 {1.2355m, 3, 1.236m}, 
861                                 {1.234567890m, 4, 1.2346m}, {1.23567890m, 2, 1.24m}, 
862                                 {47893764694.4578563236436621m, 7, 47893764694.4578563m},
863                                 {-47893764694.4578563236436621m, 9, -47893764694.457856324m},
864                                 {-47893764694.4578m, 5, -47893764694.4578m}
865                         };
866
867                         decimal d;
868
869                         for (int i = 0; i < dtab.GetLength (0); i++) {
870                                 d = Decimal.Round (dtab [i, 0], (int) dtab [i, 1]);
871                                 if (d != dtab [i, 2]) {
872                                         Assert.Fail ("Round: Round(" + dtab [i, 0] + "," + (int) dtab [i, 1] + ") != " + d);
873                                 }
874                         }
875                 }
876
877                 [Test]
878                 public void TestRoundFailures ()
879                 {
880                         decimal [,] dtab = {
881                                 {1.2345m, 3, 1.234m} 
882                         };
883
884                         decimal d;
885
886                         for (int i = 0; i < dtab.GetLength (0); i++) {
887                                 d = Decimal.Round (dtab [i, 0], (int) dtab [i, 1]);
888                                 if (d != dtab [i, 2]) {
889                                         Assert.Fail ("FailRound: Round(" + dtab [i, 0] + "," + (int) dtab [i, 1] + ") != " + d);
890                                 }
891                         }
892                 }
893
894                 [Test]
895                 public void ParseInt64 ()
896                 {
897                         long max = Int64.MaxValue;
898                         Decimal dmax = Decimal.Parse (max.ToString ());
899                         Assert.AreEqual (Int64.MaxValue, Decimal.ToInt64 (dmax), "Int64.MaxValue");
900
901                         long min = Int64.MinValue;
902                         Decimal dmin = Decimal.Parse (min.ToString ());
903                         Assert.AreEqual (Int64.MinValue, Decimal.ToInt64 (dmin), "Int64.MinValue");
904
905                         dmax += 1.1m;
906                         dmax = Decimal.Parse (dmax.ToString ());
907                         Assert.AreEqual (Int64.MaxValue, Decimal.ToInt64 (dmax - 1.1m), "Int64.MaxValue+1.1");
908
909                         dmin -= 1.1m;
910                         dmin = Decimal.Parse (dmin.ToString ());
911                         Assert.AreEqual (Int64.MinValue, Decimal.ToInt64 (dmin + 1.1m), "Int64.MinValue-1.1");
912                 }
913
914                 [Test]
915                 public void ToByte ()
916                 {
917                         Decimal d = 254.9m;
918                         Assert.AreEqual (254, Decimal.ToByte (d), "Decimal.ToByte");
919                         Assert.AreEqual (255, Convert.ToByte (d), "Convert.ToByte");
920                         Assert.AreEqual (255, (d as IConvertible).ToByte (null), "IConvertible.ToByte");
921                 }
922
923                 [Test]
924                 public void ToSByte ()
925                 {
926                         Decimal d = 126.9m;
927                         Assert.AreEqual (126, Decimal.ToSByte (d), "Decimal.ToSByte");
928                         Assert.AreEqual (127, Convert.ToSByte (d), "Convert.ToSByte");
929                         Assert.AreEqual (127, (d as IConvertible).ToSByte (null), "IConvertible.ToSByte");
930                         d = -d;
931                         Assert.AreEqual (-126, Decimal.ToSByte (d), "-Decimal.ToSByte");
932                         Assert.AreEqual (-127, Convert.ToSByte (d), "-Convert.ToSByte");
933                         Assert.AreEqual (-127, (d as IConvertible).ToSByte (null), "-IConvertible.ToSByte");
934                 }
935
936                 [Test]
937                 public void ToInt16 ()
938                 {
939                         Decimal d = 254.9m;
940                         Assert.AreEqual (254, Decimal.ToInt16 (d), "Decimal.ToInt16");
941                         Assert.AreEqual (255, Convert.ToInt16 (d), "Convert.ToInt16");
942                         Assert.AreEqual (255, (d as IConvertible).ToInt16 (null), "IConvertible.ToInt16");
943                         d = -d;
944                         Assert.AreEqual (-254, Decimal.ToInt16 (d), "-Decimal.ToInt16");
945                         Assert.AreEqual (-255, Convert.ToInt16 (d), "-Convert.ToInt16");
946                         Assert.AreEqual (-255, (d as IConvertible).ToInt16 (null), "-IConvertible.ToInt16");
947                 }
948
949                 [Test]
950                 public void ToUInt16 ()
951                 {
952                         Decimal d = 254.9m;
953                         Assert.AreEqual (254, Decimal.ToUInt16 (d), "Decimal.ToUInt16");
954                         Assert.AreEqual (255, Convert.ToUInt16 (d), "Convert.ToUInt16");
955                         Assert.AreEqual (255, (d as IConvertible).ToUInt16 (null), "IConvertible.ToUInt16");
956                 }
957
958                 [Test]
959                 public void ToInt32 ()
960                 {
961                         Decimal d = 254.9m;
962                         Assert.AreEqual (254, Decimal.ToInt32 (d), "Decimal.ToInt32");
963                         Assert.AreEqual (255, Convert.ToInt32 (d), "Convert.ToInt32");
964                         Assert.AreEqual (255, (d as IConvertible).ToInt32 (null), "IConvertible.ToInt32");
965                         d = -d;
966                         Assert.AreEqual (-254, Decimal.ToInt32 (d), "-Decimal.ToInt32");
967                         Assert.AreEqual (-255, Convert.ToInt32 (d), "-Convert.ToInt32");
968                         Assert.AreEqual (-255, (d as IConvertible).ToInt32 (null), "-IConvertible.ToInt32");
969                 }
970
971                 [Test]
972                 public void ToUInt32 ()
973                 {
974                         Decimal d = 254.9m;
975                         Assert.AreEqual (254, Decimal.ToUInt32 (d), "Decimal.ToUInt32");
976                         Assert.AreEqual (255, Convert.ToUInt32 (d), "Convert.ToUInt32");
977                         Assert.AreEqual (255, (d as IConvertible).ToUInt32 (null), "IConvertible.ToUInt32");
978                 }
979
980                 [Test]
981                 public void ToInt64 ()
982                 {
983                         Decimal d = 254.9m;
984                         Assert.AreEqual (254, Decimal.ToInt64 (d), "Decimal.ToInt64");
985                         Assert.AreEqual (255, Convert.ToInt64 (d), "Convert.ToInt64");
986                         Assert.AreEqual (255, (d as IConvertible).ToInt64 (null), "IConvertible.ToInt64");
987                         d = -d;
988                         Assert.AreEqual (-254, Decimal.ToInt64 (d), "-Decimal.ToInt64");
989                         Assert.AreEqual (-255, Convert.ToInt64 (d), "-Convert.ToInt64");
990                         Assert.AreEqual (-255, (d as IConvertible).ToInt64 (null), "-IConvertible.ToInt64");
991                 }
992
993                 [Test]
994                 [ExpectedException (typeof (OverflowException))]
995                 public void ToInt64_TooBig ()
996                 {
997                         Decimal d = (Decimal) Int64.MaxValue;
998                         d += 1.1m;
999                         long value = Decimal.ToInt64 (d);
1000                 }
1001
1002                 [Test]
1003                 [ExpectedException (typeof (OverflowException))]
1004                 public void ToInt64_TooSmall ()
1005                 {
1006                         Decimal d = (Decimal) Int64.MinValue;
1007                         d -= 1.1m;
1008                         long value = Decimal.ToInt64 (d);
1009                 }
1010
1011                 [Test]
1012                 public void ToUInt64 ()
1013                 {
1014                         Decimal d = 254.9m;
1015                         Assert.AreEqual (254, Decimal.ToUInt64 (d), "Decimal.ToUInt64");
1016                         Assert.AreEqual (255, Convert.ToUInt64 (d), "Convert.ToUInt64");
1017                         Assert.AreEqual (255, (d as IConvertible).ToUInt64 (null), "IConvertible.ToUInt64");
1018                 }
1019
1020                 [Test]
1021                 public void ToSingle ()
1022                 {
1023                         Decimal d = 254.9m;
1024                         Assert.AreEqual (254.9f, Decimal.ToSingle (d), "Decimal.ToSingle");
1025                         Assert.AreEqual (254.9f, Convert.ToSingle (d), "Convert.ToSingle");
1026                         Assert.AreEqual (254.9f, (d as IConvertible).ToSingle (null), "IConvertible.ToSingle");
1027                         d = -d;
1028                         Assert.AreEqual (-254.9f, Decimal.ToSingle (d), "-Decimal.ToSingle");
1029                         Assert.AreEqual (-254.9f, Convert.ToSingle (d), "-Convert.ToSingle");
1030                         Assert.AreEqual (-254.9f, (d as IConvertible).ToSingle (null), "-IConvertible.ToSingle");
1031                 }
1032
1033                 [Test]
1034                 public void ToDouble ()
1035                 {
1036                         Decimal d = 254.9m;
1037                         Assert.AreEqual (254.9d, Decimal.ToDouble (d), "Decimal.ToDouble");
1038                         Assert.AreEqual (254.9d, Convert.ToDouble (d), "Convert.ToDouble");
1039                         Assert.AreEqual (254.9d, (d as IConvertible).ToDouble (null), "IConvertible.ToDouble");
1040                         d = -d;
1041                         Assert.AreEqual (-254.9d, Decimal.ToDouble (d), "-Decimal.ToDouble");
1042                         Assert.AreEqual (-254.9d, Convert.ToDouble (d), "-Convert.ToDouble");
1043                         Assert.AreEqual (-254.9d, (d as IConvertible).ToDouble (null), "-IConvertible.ToDouble");
1044                 }
1045
1046                 [Test]
1047                 public void ToString_Defaults ()
1048                 {
1049                         Decimal d = 254.9m;
1050                         // everything defaults to "G"
1051                         string def = d.ToString ("G");
1052                         Assert.AreEqual (def, d.ToString (), "ToString()");
1053                         Assert.AreEqual (def, d.ToString ((IFormatProvider) null), "ToString((IFormatProvider)null)");
1054                         Assert.AreEqual (def, d.ToString ((string) null), "ToString((string)null)");
1055                         Assert.AreEqual (def, d.ToString (String.Empty), "ToString(empty)");
1056                         Assert.AreEqual (def, d.ToString (null, null), "ToString(null,null)");
1057                         Assert.AreEqual (def, d.ToString (String.Empty, null), "ToString(empty,null)");
1058
1059                         Assert.AreEqual ("254.9", def, "ToString()");
1060                 }
1061
1062                 [Test]
1063                 public void CastTruncRounding ()
1064                 {
1065                         // casting truncs decimal value (not normal nor banker's rounding)
1066                         Assert.AreEqual (254, (long) (254.9m), "254.9==254");
1067                         Assert.AreEqual (-254, (long) (-254.9m), "-254.9=-254");
1068                         Assert.AreEqual (255, (long) (255.9m), "255.9==256");
1069                         Assert.AreEqual (-255, (long) (-255.9m), "-255.9=-256");
1070                 }
1071
1072                 [Test]
1073                 public void ParseFractions ()
1074                 {
1075                         decimal d1 = Decimal.Parse ("0.523456789012345467890123456789", CultureInfo.InvariantCulture);
1076                         Assert.AreEqual (0.5234567890123454678901234568m, d1, "f1");
1077                         decimal d2 = Decimal.Parse ("0.49214206543486529434634231456", CultureInfo.InvariantCulture);
1078                         Assert.AreEqual (0.4921420654348652943463423146m, d2, "f2");
1079                 }
1080
1081                 [Test]
1082                 [ExpectedException (typeof (OverflowException))]
1083                 public void Parse_Int64_Overflow ()
1084                 {
1085                         // Int64.MaxValue + 1 + small fraction to allow 30 digits
1086                         // 123456789012345678901234567890
1087                         decimal d = Decimal.Parse ("9223372036854775808.0000000009", CultureInfo.InvariantCulture);
1088                         long l = (long) d;
1089                 }
1090
1091 #if NET_2_0
1092                 [Test]
1093                 [Category ("TargetJvmNotWorking")]
1094                 public void TryParse ()
1095                 {
1096                         Decimal r;
1097                 
1098                         // These should return false
1099                         Assert.AreEqual (false, Decimal.TryParse ("79228162514264337593543950336", out r));
1100                         Assert.AreEqual (false, Decimal.TryParse ("123nx", NumberStyles.Number, CultureInfo.InvariantCulture, out r));
1101                         Assert.AreEqual (false, Decimal.TryParse (null, NumberStyles.Number, CultureInfo.InvariantCulture, out r));
1102
1103                         // These should pass
1104                         for (int i = 0; i < tab.Length; i++) {
1105                                 Assert.AreEqual (!tab [i].exceptionFlag,
1106                                         Decimal.TryParse (tab [i].str, tab [i].style,
1107                                         NumberFormatInfo.InvariantInfo, out r));
1108                         }
1109                 }
1110 #endif
1111
1112                 [Test]
1113                 [ExpectedException (typeof (DivideByZeroException))]
1114                 public void Remainder_ByZero ()
1115                 {
1116                         Decimal.Remainder (254.9m, 0m);
1117                 }
1118
1119                 [Test]
1120                 public void Remainder ()
1121                 {
1122                         decimal p1 = 254.9m;
1123                         decimal p2 = 12.1m;
1124                         decimal n1 = -254.9m;
1125                         decimal n2 = -12.1m;
1126
1127                         Assert.AreEqual (0.8m, Decimal.Remainder (p1, p2), "254.9 % 12.1");
1128                         Assert.AreEqual (-0.8m, Decimal.Remainder (n1, p2), "-254.9 % 12.1");
1129                         Assert.AreEqual (0.8m, Decimal.Remainder (p1, n2), "254.9 % -12.1");
1130                         Assert.AreEqual (-0.8m, Decimal.Remainder (n1, n2), "-254.9 % -12.1");
1131
1132                         Assert.AreEqual (12.1m, Decimal.Remainder (p2, p1), "12.1 % 254.9");
1133                         Assert.AreEqual (-12.1m, Decimal.Remainder (n2, p1), "-12.1 % 254.9");
1134                         Assert.AreEqual (12.1m, Decimal.Remainder (p2, n1), "12.1 % -254.9");
1135                         Assert.AreEqual (-12.1m, Decimal.Remainder (n2, n1), "-12.1 % -254.9");
1136 #if NET_2_0
1137                         Assert.AreEqual (0.0m, Decimal.Remainder (p1, p1), "12.1 % 12.1");
1138                         Assert.AreEqual (0.0m, Decimal.Remainder (n1, p1), "-12.1 % 12.1");
1139                         Assert.AreEqual (0.0m, Decimal.Remainder (p1, n1), "12.1 % -12.1");
1140                         Assert.AreEqual (0.0m, Decimal.Remainder (n1, n1), "-12.1 % -12.1");
1141 #else
1142                         Assert.AreEqual (0, Decimal.Remainder (p1, p1), "12.1 % 12.1");
1143                         Assert.AreEqual (0, Decimal.Remainder (n1, p1), "-12.1 % 12.1");
1144                         Assert.AreEqual (0, Decimal.Remainder (p1, n1), "12.1 % -12.1");
1145                         Assert.AreEqual (0, Decimal.Remainder (n1, n1), "-12.1 % -12.1");
1146 #endif
1147                 }
1148
1149                 [Test]
1150                 public void Remainder2 ()
1151                 {
1152                         decimal a = 20.0M;
1153                         decimal b = 10.0M;
1154                         decimal c = 10.00M;
1155
1156                         Assert.AreEqual (0.00m, a % c, "20.0M % 10.00M");
1157                 
1158                 }
1159
1160                 [Test]
1161                 [ExpectedException (typeof (DivideByZeroException))]
1162                 public void Divide_ByZero ()
1163                 {
1164                         Decimal.Divide (254.9m, 0m);
1165                 }
1166
1167                 [Test]
1168                 public void Divide ()
1169                 {
1170                         decimal p1 = 254.9m;
1171                         decimal p2 = 12.1m;
1172                         decimal n1 = -254.9m;
1173                         decimal n2 = -12.1m;
1174
1175                         decimal c1 = 21.066115702479338842975206612m;
1176                         decimal c2 = 0.0474695959199686151431934092m;
1177
1178                         Assert.AreEqual (c1, Decimal.Divide (p1, p2), "254.9 / 12.1");
1179                         Assert.AreEqual (-c1, Decimal.Divide (n1, p2), "-254.9 / 12.1");
1180                         Assert.AreEqual (-c1, Decimal.Divide (p1, n2), "254.9 / -12.1");
1181                         Assert.AreEqual (c1, Decimal.Divide (n1, n2), "-254.9 / -12.1");
1182
1183                         Assert.AreEqual (c2, Decimal.Divide (p2, p1), "12.1 / 254.9");
1184                         Assert.AreEqual (-c2, Decimal.Divide (n2, p1), "-12.1 / 254.9");
1185                         Assert.AreEqual (-c2, Decimal.Divide (p2, n1), "12.1 / -254.9");
1186                         Assert.AreEqual (c2, Decimal.Divide (n2, n1), "-12.1 / -254.9");
1187
1188                         Assert.AreEqual (1, Decimal.Divide (p1, p1), "12.1 / 12.1");
1189                         Assert.AreEqual (-1, Decimal.Divide (n1, p1), "-12.1 / 12.1");
1190                         Assert.AreEqual (-1, Decimal.Divide (p1, n1), "12.1 / -12.1");
1191                         Assert.AreEqual (1, Decimal.Divide (n1, n1), "-12.1 / -12.1");
1192                 }
1193
1194                 [Test]
1195                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1196                 public void Round_InvalidDecimals_Negative ()
1197                 {
1198                         Decimal.Round (254.9m, -1);
1199                 }
1200
1201                 [Test]
1202                 [ExpectedException (typeof (ArgumentOutOfRangeException))]
1203                 public void Round_InvalidDecimals_TooHigh ()
1204                 {
1205                         Decimal.Round (254.9m, 29);
1206                 }
1207
1208                 [Test]
1209                 public void Round_OddValue ()
1210                 {
1211                         decimal five = 5.5555555555555555555555555555m;
1212                         Assert.AreEqual (6, Decimal.Round (five, 0), "5,5_,00");
1213                         Assert.AreEqual (5.6m, Decimal.Round (five, 1), "5,5_,01");
1214                         Assert.AreEqual (5.56m, Decimal.Round (five, 2), "5,5_,02");
1215                         Assert.AreEqual (5.556m, Decimal.Round (five, 3), "5,5_,03");
1216                         Assert.AreEqual (5.5556m, Decimal.Round (five, 4), "5,5_,04");
1217                         Assert.AreEqual (5.55556m, Decimal.Round (five, 5), "5,5_,05");
1218                         Assert.AreEqual (5.555556m, Decimal.Round (five, 6), "5,5_,06");
1219                         Assert.AreEqual (5.5555556m, Decimal.Round (five, 7), "5,5_,07");
1220                         Assert.AreEqual (5.55555556m, Decimal.Round (five, 8), "5,5_,08");
1221                         Assert.AreEqual (5.555555556m, Decimal.Round (five, 9), "5,5_,09");
1222                         Assert.AreEqual (5.5555555556m, Decimal.Round (five, 10), "5,5_,10");
1223                         Assert.AreEqual (5.55555555556m, Decimal.Round (five, 11), "5,5_,11");
1224                         Assert.AreEqual (5.555555555556m, Decimal.Round (five, 12), "5,5_,12");
1225                         Assert.AreEqual (5.5555555555556m, Decimal.Round (five, 13), "5,5_,13");
1226                         Assert.AreEqual (5.55555555555556m, Decimal.Round (five, 14), "5,5_,14");
1227                         Assert.AreEqual (5.555555555555556m, Decimal.Round (five, 15), "5,5_,15");
1228                         Assert.AreEqual (5.5555555555555556m, Decimal.Round (five, 16), "5,5_,16");
1229                         Assert.AreEqual (5.55555555555555556m, Decimal.Round (five, 17), "5,5_,17");
1230                         Assert.AreEqual (5.555555555555555556m, Decimal.Round (five, 18), "5,5_,18");
1231                         Assert.AreEqual (5.5555555555555555556m, Decimal.Round (five, 19), "5,5_,19");
1232                         Assert.AreEqual (5.55555555555555555556m, Decimal.Round (five, 20), "5,5_,20");
1233                         Assert.AreEqual (5.555555555555555555556m, Decimal.Round (five, 21), "5,5_,21");
1234                         Assert.AreEqual (5.5555555555555555555556m, Decimal.Round (five, 22), "5,5_,22");
1235                         Assert.AreEqual (5.55555555555555555555556m, Decimal.Round (five, 23), "5,5_,23");
1236                         Assert.AreEqual (5.555555555555555555555556m, Decimal.Round (five, 24), "5,5_,24");
1237                         Assert.AreEqual (5.5555555555555555555555556m, Decimal.Round (five, 25), "5,5_,25");
1238                         Assert.AreEqual (5.55555555555555555555555556m, Decimal.Round (five, 26), "5,5_,26");
1239                         Assert.AreEqual (5.555555555555555555555555556m, Decimal.Round (five, 27), "5,5_,27");
1240                         Assert.AreEqual (5.5555555555555555555555555555m, Decimal.Round (five, 28), "5.5_,28");
1241                 }
1242
1243                 [Test]
1244                 public void Round_EvenValue ()
1245                 {
1246                         Assert.AreEqual (2, Decimal.Round (2.5m, 0), "2,2_5,00");
1247                         Assert.AreEqual (2.2m, Decimal.Round (2.25m, 1), "2,2_5,01");
1248                         Assert.AreEqual (2.22m, Decimal.Round (2.225m, 2), "2,2_5,02");
1249                         Assert.AreEqual (2.222m, Decimal.Round (2.2225m, 3), "2,2_5,03");
1250                         Assert.AreEqual (2.2222m, Decimal.Round (2.22225m, 4), "2,2_5,04");
1251                         Assert.AreEqual (2.22222m, Decimal.Round (2.222225m, 5), "2,2_5,05");
1252                         Assert.AreEqual (2.222222m, Decimal.Round (2.2222225m, 6), "2,2_5,06");
1253                         Assert.AreEqual (2.2222222m, Decimal.Round (2.22222225m, 7), "2,2_5,07");
1254                         Assert.AreEqual (2.22222222m, Decimal.Round (2.222222225m, 8), "2,2_5,08");
1255                         Assert.AreEqual (2.222222222m, Decimal.Round (2.2222222225m, 9), "2,2_5,09");
1256                         Assert.AreEqual (2.2222222222m, Decimal.Round (2.22222222225m, 10), "2,2_5,10");
1257                         Assert.AreEqual (2.22222222222m, Decimal.Round (2.222222222225m, 11), "2,2_5,11");
1258                         Assert.AreEqual (2.222222222222m, Decimal.Round (2.2222222222225m, 12), "2,2_5,12");
1259                         Assert.AreEqual (2.2222222222222m, Decimal.Round (2.22222222222225m, 13), "2,2_5,13");
1260                         Assert.AreEqual (2.22222222222222m, Decimal.Round (2.222222222222225m, 14), "2,2_5,14");
1261                         Assert.AreEqual (2.222222222222222m, Decimal.Round (2.2222222222222225m, 15), "2,2_5,15");
1262                         Assert.AreEqual (2.2222222222222222m, Decimal.Round (2.22222222222222225m, 16), "2,2_5,16");
1263                         Assert.AreEqual (2.22222222222222222m, Decimal.Round (2.222222222222222225m, 17), "2,2_5,17");
1264                         Assert.AreEqual (2.222222222222222222m, Decimal.Round (2.2222222222222222225m, 18), "2,2_5,18");
1265                         Assert.AreEqual (2.2222222222222222222m, Decimal.Round (2.22222222222222222225m, 19), "2,2_5,19");
1266                         Assert.AreEqual (2.22222222222222222222m, Decimal.Round (2.222222222222222222225m, 20), "2,2_5,20");
1267                         Assert.AreEqual (2.222222222222222222222m, Decimal.Round (2.2222222222222222222225m, 21), "2,2_5,21");
1268                         Assert.AreEqual (2.2222222222222222222222m, Decimal.Round (2.22222222222222222222225m, 22), "2,2_5,22");
1269                         Assert.AreEqual (2.22222222222222222222222m, Decimal.Round (2.222222222222222222222225m, 23), "2,2_5,23");
1270                         Assert.AreEqual (2.222222222222222222222222m, Decimal.Round (2.2222222222222222222222225m, 24), "2,2_5,24");
1271                         Assert.AreEqual (2.2222222222222222222222222m, Decimal.Round (2.22222222222222222222222225m, 25), "2,2_5,25");
1272                         Assert.AreEqual (2.22222222222222222222222222m, Decimal.Round (2.222222222222222222222222225m, 26), "2,2_5,26");
1273                         Assert.AreEqual (2.222222222222222222222222222m, Decimal.Round (2.2222222222222222222222222225m, 27), "2,2_5,27");
1274                         Assert.AreEqual (2.2222222222222222222222222222m, Decimal.Round (2.22222222222222222222222222225m, 28), "2,2_5,28");
1275                 }
1276
1277                 [Test]
1278                 public void Round_OddValue_Negative ()
1279                 {
1280                         decimal five = -5.5555555555555555555555555555m;
1281                         Assert.AreEqual (-6, Decimal.Round (five, 0), "-5,5_,00");
1282                         Assert.AreEqual (-5.6m, Decimal.Round (five, 1), "-5,5_,01");
1283                         Assert.AreEqual (-5.56m, Decimal.Round (five, 2), "-5,5_,02");
1284                         Assert.AreEqual (-5.556m, Decimal.Round (five, 3), "-5,5_,03");
1285                         Assert.AreEqual (-5.5556m, Decimal.Round (five, 4), "-5,5_,04");
1286                         Assert.AreEqual (-5.55556m, Decimal.Round (five, 5), "-5,5_,05");
1287                         Assert.AreEqual (-5.555556m, Decimal.Round (five, 6), "-5,5_,06");
1288                         Assert.AreEqual (-5.5555556m, Decimal.Round (five, 7), "-5,5_,07");
1289                         Assert.AreEqual (-5.55555556m, Decimal.Round (five, 8), "-5,5_,08");
1290                         Assert.AreEqual (-5.555555556m, Decimal.Round (five, 9), "-5,5_,09");
1291                         Assert.AreEqual (-5.5555555556m, Decimal.Round (five, 10), "-5,5_,10");
1292                         Assert.AreEqual (-5.55555555556m, Decimal.Round (five, 11), "-5,5_,11");
1293                         Assert.AreEqual (-5.555555555556m, Decimal.Round (five, 12), "-5,5_,12");
1294                         Assert.AreEqual (-5.5555555555556m, Decimal.Round (five, 13), "-5,5_,13");
1295                         Assert.AreEqual (-5.55555555555556m, Decimal.Round (five, 14), "-5,5_,14");
1296                         Assert.AreEqual (-5.555555555555556m, Decimal.Round (five, 15), "-5,5_,15");
1297                         Assert.AreEqual (-5.5555555555555556m, Decimal.Round (five, 16), "-5,5_,16");
1298                         Assert.AreEqual (-5.55555555555555556m, Decimal.Round (five, 17), "-5,5_,17");
1299                         Assert.AreEqual (-5.555555555555555556m, Decimal.Round (five, 18), "-5,5_,18");
1300                         Assert.AreEqual (-5.5555555555555555556m, Decimal.Round (five, 19), "-5,5_,19");
1301                         Assert.AreEqual (-5.55555555555555555556m, Decimal.Round (five, 20), "-5,5_,20");
1302                         Assert.AreEqual (-5.555555555555555555556m, Decimal.Round (five, 21), "-5,5_,21");
1303                         Assert.AreEqual (-5.5555555555555555555556m, Decimal.Round (five, 22), "-5,5_,22");
1304                         Assert.AreEqual (-5.55555555555555555555556m, Decimal.Round (five, 23), "-5,5_,23");
1305                         Assert.AreEqual (-5.555555555555555555555556m, Decimal.Round (five, 24), "-5,5_,24");
1306                         Assert.AreEqual (-5.5555555555555555555555556m, Decimal.Round (five, 25), "-5,5_,25");
1307                         Assert.AreEqual (-5.55555555555555555555555556m, Decimal.Round (five, 26), "-5,5_,26");
1308                         Assert.AreEqual (-5.555555555555555555555555556m, Decimal.Round (five, 27), "-5,5_,27");
1309                         Assert.AreEqual (-5.5555555555555555555555555555m, Decimal.Round (five, 28), "-5.5_,28");
1310                 }
1311
1312                 [Test]
1313                 public void Round_EvenValue_Negative ()
1314                 {
1315                         Assert.AreEqual (-2, Decimal.Round (-2.5m, 0), "-2,2_5,00");
1316                         Assert.AreEqual (-2.2m, Decimal.Round (-2.25m, 1), "-2,2_5,01");
1317                         Assert.AreEqual (-2.22m, Decimal.Round (-2.225m, 2), "-2,2_5,02");
1318                         Assert.AreEqual (-2.222m, Decimal.Round (-2.2225m, 3), "-2,2_5,03");
1319                         Assert.AreEqual (-2.2222m, Decimal.Round (-2.22225m, 4), "-2,2_5,04");
1320                         Assert.AreEqual (-2.22222m, Decimal.Round (-2.222225m, 5), "-2,2_5,05");
1321                         Assert.AreEqual (-2.222222m, Decimal.Round (-2.2222225m, 6), "-2,2_5,06");
1322                         Assert.AreEqual (-2.2222222m, Decimal.Round (-2.22222225m, 7), "-2,2_5,07");
1323                         Assert.AreEqual (-2.22222222m, Decimal.Round (-2.222222225m, 8), "-2,2_5,08");
1324                         Assert.AreEqual (-2.222222222m, Decimal.Round (-2.2222222225m, 9), "-2,2_5,09");
1325                         Assert.AreEqual (-2.2222222222m, Decimal.Round (-2.22222222225m, 10), "-2,2_5,10");
1326                         Assert.AreEqual (-2.22222222222m, Decimal.Round (-2.222222222225m, 11), "-2,2_5,11");
1327                         Assert.AreEqual (-2.222222222222m, Decimal.Round (-2.2222222222225m, 12), "-2,2_5,12");
1328                         Assert.AreEqual (-2.2222222222222m, Decimal.Round (-2.22222222222225m, 13), "-2,2_5,13");
1329                         Assert.AreEqual (-2.22222222222222m, Decimal.Round (-2.222222222222225m, 14), "-2,2_5,14");
1330                         Assert.AreEqual (-2.222222222222222m, Decimal.Round (-2.2222222222222225m, 15), "-2,2_5,15");
1331                         Assert.AreEqual (-2.2222222222222222m, Decimal.Round (-2.22222222222222225m, 16), "-2,2_5,16");
1332                         Assert.AreEqual (-2.22222222222222222m, Decimal.Round (-2.222222222222222225m, 17), "-2,2_5,17");
1333                         Assert.AreEqual (-2.222222222222222222m, Decimal.Round (-2.2222222222222222225m, 18), "-2,2_5,18");
1334                         Assert.AreEqual (-2.2222222222222222222m, Decimal.Round (-2.22222222222222222225m, 19), "-2,2_5,19");
1335                         Assert.AreEqual (-2.22222222222222222222m, Decimal.Round (-2.222222222222222222225m, 20), "-2,2_5,20");
1336                         Assert.AreEqual (-2.222222222222222222222m, Decimal.Round (-2.2222222222222222222225m, 21), "-2,2_5,21");
1337                         Assert.AreEqual (-2.2222222222222222222222m, Decimal.Round (-2.22222222222222222222225m, 22), "-2,2_5,22");
1338                         Assert.AreEqual (-2.22222222222222222222222m, Decimal.Round (-2.222222222222222222222225m, 23), "-2,2_5,23");
1339                         Assert.AreEqual (-2.222222222222222222222222m, Decimal.Round (-2.2222222222222222222222225m, 24), "-2,2_5,24");
1340                         Assert.AreEqual (-2.2222222222222222222222222m, Decimal.Round (-2.22222222222222222222222225m, 25), "-2,2_5,25");
1341                         Assert.AreEqual (-2.22222222222222222222222222m, Decimal.Round (-2.222222222222222222222222225m, 26), "-2,2_5,26");
1342                         Assert.AreEqual (-2.222222222222222222222222222m, Decimal.Round (-2.2222222222222222222222222225m, 27), "-2,2_5,27");
1343                         Assert.AreEqual (-2.2222222222222222222222222222m, Decimal.Round (-2.22222222222222222222222222225m, 28), "-2,2_5,28");
1344                 }
1345
1346                 [Test] // bug #59425
1347                 public void ParseAndKeepPrecision ()
1348                 {
1349                         string value = "5";
1350                         Assert.AreEqual (value, value, Decimal.Parse (value).ToString ());
1351                         value += '.';
1352                         for (int i = 0; i < 28; i++) {
1353                                 value += "0";
1354                                 Assert.AreEqual (value, Decimal.Parse (value).ToString (), i.ToString ());
1355                         }
1356
1357                         value = "-5";
1358                         Assert.AreEqual (value, value, Decimal.Parse (value).ToString ());
1359                         value += '.';
1360                         for (int i = 0; i < 28; i++) {
1361                                 value += "0";
1362                                 Assert.AreEqual (value, Decimal.Parse (value).ToString (), "-" + i.ToString ());
1363                         }
1364                 }
1365
1366                 [Test]
1367                 public void ToString_G ()
1368                 {
1369                         Assert.AreEqual ("1.0", (1.0m).ToString (), "00");
1370                         Assert.AreEqual ("0.1", (0.1m).ToString (), "01");
1371                         Assert.AreEqual ("0.01", (0.01m).ToString (), "02");
1372                         Assert.AreEqual ("0.001", (0.001m).ToString (), "03");
1373                         Assert.AreEqual ("0.0001", (0.0001m).ToString (), "04");
1374                         Assert.AreEqual ("0.00001", (0.00001m).ToString (), "05");
1375                         Assert.AreEqual ("0.000001", (0.000001m).ToString (), "06");
1376                         Assert.AreEqual ("0.0000001", (0.0000001m).ToString (), "07");
1377                         Assert.AreEqual ("0.00000001", (0.00000001m).ToString (), "08");
1378                         Assert.AreEqual ("0.000000001", (0.000000001m).ToString (), "09");
1379                         Assert.AreEqual ("0.0000000001", (0.0000000001m).ToString (), "10");
1380                         Assert.AreEqual ("0.00000000001", (0.00000000001m).ToString (), "11");
1381                         Assert.AreEqual ("0.000000000001", (0.000000000001m).ToString (), "12");
1382                         Assert.AreEqual ("0.0000000000001", (0.0000000000001m).ToString (), "13");
1383                         Assert.AreEqual ("0.00000000000001", (0.00000000000001m).ToString (), "14");
1384                         Assert.AreEqual ("0.000000000000001", (0.000000000000001m).ToString (), "15");
1385                         Assert.AreEqual ("0.0000000000000001", (0.0000000000000001m).ToString (), "16");
1386                         Assert.AreEqual ("0.00000000000000001", (0.00000000000000001m).ToString (), "17");
1387                         Assert.AreEqual ("0.000000000000000001", (0.000000000000000001m).ToString (), "18");
1388                         Assert.AreEqual ("0.0000000000000000001", (0.0000000000000000001m).ToString (), "19");
1389                         Assert.AreEqual ("0.00000000000000000001", (0.00000000000000000001m).ToString (), "20");
1390                         Assert.AreEqual ("0.000000000000000000001", (0.000000000000000000001m).ToString (), "21");
1391                         Assert.AreEqual ("0.0000000000000000000001", (0.0000000000000000000001m).ToString (), "22");
1392                         Assert.AreEqual ("0.00000000000000000000001", (0.00000000000000000000001m).ToString (), "23");
1393                         Assert.AreEqual ("0.000000000000000000000001", (0.000000000000000000000001m).ToString (), "24");
1394                         Assert.AreEqual ("0.0000000000000000000000001", (0.0000000000000000000000001m).ToString (), "25");
1395                         Assert.AreEqual ("0.00000000000000000000000001", (0.00000000000000000000000001m).ToString (), "26");
1396                         Assert.AreEqual ("0.000000000000000000000000001", (0.000000000000000000000000001m).ToString (), "27");
1397                         Assert.AreEqual ("0.0000000000000000000000000001", (0.0000000000000000000000000001m).ToString (), "28");
1398                 }
1399
1400 #if NET_2_0
1401                 [Test]
1402                 public void MidpointRoundingAwayFromZero ()
1403                 {
1404                         MidpointRounding m = MidpointRounding.AwayFromZero;
1405                         Assert.AreEqual (4, Math.Round (3.5M, m), "#1");
1406                         Assert.AreEqual (3, Math.Round (2.8M, m), "#2");
1407                         Assert.AreEqual (3, Math.Round (2.5M, m), "#3");
1408                         Assert.AreEqual (2, Math.Round (2.1M, m), "#4");
1409                         Assert.AreEqual (-2, Math.Round (-2.1M, m), "#5");
1410                         Assert.AreEqual (-3, Math.Round (-2.5M, m), "#6");
1411                         Assert.AreEqual (-3, Math.Round (-2.8M, m), "#7");
1412                         Assert.AreEqual (-4, Math.Round (-3.5M, m), "#8");
1413
1414                         Assert.AreEqual (3.1M, Math.Round (3.05M, 1, m), "#9");
1415                         Assert.AreEqual (2.1M, Math.Round (2.08M, 1, m), "#10");
1416                         Assert.AreEqual (2.1M, Math.Round (2.05M, 1, m), "#11");
1417                         Assert.AreEqual (2.0M, Math.Round (2.01M, 1, m), "#12");
1418                         Assert.AreEqual (-2.0M, Math.Round (-2.01M, 1, m), "#13");
1419                         Assert.AreEqual (-2.1M, Math.Round (-2.05M, 1, m), "#14");
1420                         Assert.AreEqual (-2.1M, Math.Round (-2.08M, 1, m), "#15");
1421                         Assert.AreEqual (-3.1M, Math.Round (-3.05M, 1, m), "#16");
1422                 }
1423 #endif
1424         }
1425 }