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