1+ module ctoriiibby
2+
3+ //<Snippet2>
4+ // Example of the decimal( int, int, int, bool, byte ) constructor.
5+ open System
6+
7+ // Get the exception type name; remove the namespace prefix.
8+ let getExceptionType ( ex : exn ) =
9+ let exceptionType = ex.GetType() |> string
10+ exceptionType.Substring( exceptionType.LastIndexOf '.' + 1 )
11+
12+ // Create a decimal object and display its value.
13+ let createDecimal low mid high ( isNeg : bool ) ( scale : byte ) =
14+ // Format the constructor for display.
15+ let ctor =
16+ $" decimal( %i {low}, %i {mid}, %i {high}, {isNeg}, {scale} )"
17+
18+ let valOrExc =
19+ try
20+ // Construct the decimal value.
21+ let decimalNum = new decimal( low, mid, high, isNeg, scale)
22+
23+ // Format and save the decimal value.
24+ decimalNum |> string
25+ with ex ->
26+ // Save the exception type if an exception was thrown.
27+ getExceptionType ex
28+
29+ // Display the constructor and decimal value or exception.
30+ let ctorLen = 76 - valOrExc.Length
31+
32+ // Display the data on one line if it will fit.
33+ if ctorLen > ctor.Length then
34+ printfn $" {ctor.PadRight ctorLen}{valOrExc}"
35+
36+ // Otherwise, display the data on two lines.
37+ else
38+ printfn $" {ctor}"
39+ printfn $" {valOrExc,76}"
40+
41+ printfn
42+ """ This example of the decimal(int, int, int, bool, byte)
43+ constructor generates the following output.
44+ """
45+ printfn " %-38s%38s " " Constructor" " Value or Exception"
46+ printfn " %-38s%38s " " -----------" " ------------------"
47+
48+ // Construct decimal objects from the component fields.
49+ createDecimal 0 0 0 false 0 uy
50+ createDecimal 0 0 0 false 27 uy
51+ createDecimal 0 0 0 true 0 uy
52+ createDecimal 1000000000 0 0 false 0 uy
53+ createDecimal 0 1000000000 0 false 0 uy
54+ createDecimal 0 0 1000000000 false 0 uy
55+ createDecimal 1000000000 1000000000 1000000000 false 0 uy
56+ createDecimal - 1 - 1 - 1 false 0 uy
57+ createDecimal - 1 - 1 - 1 true 0 uy
58+ createDecimal - 1 - 1 - 1 false 15 uy
59+ createDecimal - 1 - 1 - 1 false 28 uy
60+ createDecimal - 1 - 1 - 1 false 29 uy
61+ createDecimal Int32.MaxValue 0 0 false 18 uy
62+ createDecimal Int32.MaxValue 0 0 false 28 uy
63+ createDecimal Int32.MaxValue 0 0 true 28 uy
64+
65+
66+ // This example of the decimal(int, int, int, bool, byte)
67+ // constructor generates the following output.
68+ //
69+ // Constructor Value or Exception
70+ // ----------- ------------------
71+ // decimal( 0, 0, 0, False, 0 ) 0
72+ // decimal( 0, 0, 0, False, 27 ) 0
73+ // decimal( 0, 0, 0, True, 0 ) 0
74+ // decimal( 1000000000, 0, 0, False, 0 ) 1000000000
75+ // decimal( 0, 1000000000, 0, False, 0 ) 4294967296000000000
76+ // decimal( 0, 0, 1000000000, False, 0 ) 18446744073709551616000000000
77+ // decimal( 1000000000, 1000000000, 1000000000, False, 0 )
78+ // 18446744078004518913000000000
79+ // decimal( -1, -1, -1, False, 0 ) 79228162514264337593543950335
80+ // decimal( -1, -1, -1, True, 0 ) -79228162514264337593543950335
81+ // decimal( -1, -1, -1, False, 15 ) 79228162514264.337593543950335
82+ // decimal( -1, -1, -1, False, 28 ) 7.9228162514264337593543950335
83+ // decimal( -1, -1, -1, False, 29 ) ArgumentOutOfRangeException
84+ // decimal( 2147483647, 0, 0, False, 18 ) 0.000000002147483647
85+ // decimal( 2147483647, 0, 0, False, 28 ) 0.0000000000000000002147483647
86+ // decimal( 2147483647, 0, 0, True, 28 ) -0.0000000000000000002147483647
87+ //</Snippet2>
0 commit comments