diff --git a/snippets/fsharp/System/Decimal/.ctor/ctor2a.fs b/snippets/fsharp/System/Decimal/.ctor/ctor2a.fs new file mode 100644 index 00000000000..fcc252920be --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctor2a.fs @@ -0,0 +1,18 @@ +module ctor2a + +// +open System + +let values = [ 1234.96m; -1234.96m ] +for value in values do + let parts = Decimal.GetBits value + let sign = (parts[3] &&& 0x80000000) <> 0 + + let scale = (parts[3] >>> 16) &&& 0x7F |> byte + let newValue = Decimal(parts[0], parts[1], parts[2], sign, scale) + printfn $"{value} --> {newValue}" + +// The example displays the following output: +// 1234.96 --> 1234.96 +// -1234.96 --> -1234.96 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctordo.fs b/snippets/fsharp/System/Decimal/.ctor/ctordo.fs new file mode 100644 index 00000000000..1af8d5efbb9 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctordo.fs @@ -0,0 +1,56 @@ +module ctordo + +// +// Example of the decimal( double ) constructor. +open System + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Create a decimal object and display its value. +let createDecimal (value: double) valToStr = + // Format and display the constructor. + printf "%-34s" $"decimal( {valToStr} )" + + try + // Construct the decimal value. + let decimalNum = Decimal value + + // Display the value if it was created successfully. + printfn $"{decimalNum,31}" + with ex -> + // Display the exception type if an exception was thrown. + printfn $"{getExceptionType ex,31}" + +printfn $"This example of the decimal( double ) constructor \ngenerates the following output.\n" +printfn "%-34s%31s" "Constructor" "Value or Exception" +printfn "%-34s%31s" "-----------" "------------------" + +// Construct decimal objects from double values. +createDecimal 1.23456789E+5 "1.23456789E+5" +createDecimal 1.234567890123E+15 "1.234567890123E+15" +createDecimal 1.2345678901234567E+25 "1.2345678901234567E+25" +createDecimal 1.2345678901234567E+35 "1.2345678901234567E+35" +createDecimal 1.23456789E-5 "1.23456789E-5" +createDecimal 1.234567890123E-15 "1.234567890123E-15" +createDecimal 1.2345678901234567E-25 "1.2345678901234567E-25" +createDecimal 1.2345678901234567E-35 "1.2345678901234567E-35" +createDecimal (1. / 7.) "1. / 7." + + +// This example of the decimal( double ) constructor +// generates the following output. +// +// Constructor Value or Exception +// ----------- ------------------ +// decimal( 1.23456789E+5 ) 123456.789 +// decimal( 1.234567890123E+15 ) 1234567890123000 +// decimal( 1.2345678901234567E+25 ) 12345678901234600000000000 +// decimal( 1.2345678901234567E+35 ) OverflowException +// decimal( 1.23456789E-5 ) 0.0000123456789 +// decimal( 1.234567890123E-15 ) 0.000000000000001234567890123 +// decimal( 1.2345678901234567E-25 ) 0.0000000000000000000000001235 +// decimal( 1.2345678901234567E-35 ) 0 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctori.fs b/snippets/fsharp/System/Decimal/.ctor/ctori.fs new file mode 100644 index 00000000000..fd7e4730d2e --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctori.fs @@ -0,0 +1,41 @@ +module ctori + +// +// Example of the decimal(int) constructor. +open System + +// Create a decimal object and display its value. +let createDecimal (value: int) valToStr = + let decimalNum = new decimal(value) + + // Format the constructor for display. + let ctor = $"decimal( {valToStr} )" + + // Display the constructor and its value. + printfn $"{ctor,-30}{decimalNum,16}" + +printfn "This example of the decimal(int) constructor\ngenerates the following output.\n" +printfn "%-30s%16s" "Constructor" "Value" +printfn "%-30s%16s" "-----------" "-----" + +// Construct decimal objects from int values. +createDecimal Int32.MinValue "Int32.MinValue" +createDecimal Int32.MaxValue "int.MaxValue" +createDecimal 0 "0" +createDecimal 999999999 "999999999" +createDecimal 0x40000000 "0x40000000" +createDecimal (int 0xC0000000) "int 0xC0000000" + + +// This example of the decimal(int) constructor +// generates the following output. + +// Constructor Value +// ----------- ----- +// decimal( Int32.MinValue ) -2147483648 +// decimal( Int32.MaxValue ) 2147483647 +// decimal( 0 ) 0 +// decimal( 999999999 ) 999999999 +// decimal( 0x40000000 ) 1073741824 +// decimal( int 0xC0000000 ) -1073741824 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctoriarr.fs b/snippets/fsharp/System/Decimal/.ctor/ctoriarr.fs new file mode 100644 index 00000000000..61ec47256a2 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctoriarr.fs @@ -0,0 +1,90 @@ +module ctoriarr + +// +// Example of the decimal(int[]) constructor. +open System + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Create a decimal object and display its value. +let createDecimal (bits: int[]) = + // Format the constructor for display. + let mutable ctor = String.Format("decimal( {{ 0x{0:X}", bits[0]) + + for i = 1 to bits.Length - 1 do + ctor <- $"{ctor}, 0x{bits[i]:X}" + ctor <- ctor + " } )" + + let valOrExc = + try + // Construct the decimal value. + let decimalNum = new decimal(bits) + + // Format the decimal value for display. + string decimalNum + with ex -> + // Save the exception type if an exception was thrown. + getExceptionType ex + + // Display the constructor and decimal value or exception. + let ctorLen = 76 - valOrExc.Length; + + // Display the data on one line if it will fit. + if ctorLen > ctor.Length then + printfn $"{ctor.PadRight ctorLen}{valOrExc}" + + // Otherwise, display the data on two lines. + else + printfn $"{ctor}" + printfn $"{valOrExc,76}" + +printfn + """This example of the decimal(int[]) constructor +generates the following output. +""" +printfn "%-38s%38s" "Constructor" "Value or Exception" +printfn "%-38s%38s" "-----------" "------------------" + +// Construct decimal objects from integer arrays. +createDecimal [| 0; 0; 0; 0 |] +createDecimal [| 0; 0; 0 |] +createDecimal [| 0; 0; 0; 0; 0 |] +createDecimal [| 1000000000; 0; 0; 0 |] +createDecimal [| 0; 1000000000; 0; 0 |] +createDecimal [| 0; 0; 1000000000; 0 |] +createDecimal [| 0; 0; 0; 1000000000 |] +createDecimal [| -1; -1; -1; 0 |] +createDecimal [| -1; -1; -1; 0x80000000 |] +createDecimal [| -1; 0; 0; 0x100000 |] +createDecimal [| -1; 0; 0; 0x1C0000 |] +createDecimal [| -1; 0; 0; 0x1D0000 |] +createDecimal [| -1; 0; 0; 0x1C0001 |] +createDecimal [| 0xF0000; 0xF0000; 0xF0000; 0xF0000 |] + + +// This example of the decimal(int[]) constructor +// generates the following output. +// +// Constructor Value or Exception +// ----------- ------------------ +// decimal( { 0x0, 0x0, 0x0, 0x0 } ) 0 +// decimal( { 0x0, 0x0, 0x0 } ) ArgumentException +// decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } ) ArgumentException +// decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } ) 1000000000 +// decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } ) 4294967296000000000 +// decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } ) 18446744073709551616000000000 +// decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } ) ArgumentException +// decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } ) +// 79228162514264337593543950335 +// decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } ) +// -79228162514264337593543950335 +// decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } ) 0.0000004294967295 +// decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295 +// decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } ) ArgumentException +// decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } ) ArgumentException +// decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } ) +// 18133887298.441562272235520 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctoriiibby.fs b/snippets/fsharp/System/Decimal/.ctor/ctoriiibby.fs new file mode 100644 index 00000000000..664c84bc547 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctoriiibby.fs @@ -0,0 +1,87 @@ +module ctoriiibby + +// +// Example of the decimal( int, int, int, bool, byte ) constructor. +open System + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Create a decimal object and display its value. +let createDecimal low mid high (isNeg: bool) (scale: byte) = + // Format the constructor for display. + let ctor = + $"decimal( %i{low}, %i{mid}, %i{high}, {isNeg}, {scale} )" + + let valOrExc = + try + // Construct the decimal value. + let decimalNum = new decimal(low, mid, high, isNeg, scale) + + // Format and save the decimal value. + decimalNum |> string + with ex -> + // Save the exception type if an exception was thrown. + getExceptionType ex + + // Display the constructor and decimal value or exception. + let ctorLen = 76 - valOrExc.Length + + // Display the data on one line if it will fit. + if ctorLen > ctor.Length then + printfn $"{ctor.PadRight ctorLen}{valOrExc}" + + // Otherwise, display the data on two lines. + else + printfn $"{ctor}" + printfn $"{valOrExc,76}" + +printfn + """This example of the decimal(int, int, int, bool, byte) +constructor generates the following output. +""" +printfn "%-38s%38s" "Constructor" "Value or Exception" +printfn "%-38s%38s" "-----------" "------------------" + +// Construct decimal objects from the component fields. +createDecimal 0 0 0 false 0uy +createDecimal 0 0 0 false 27uy +createDecimal 0 0 0 true 0uy +createDecimal 1000000000 0 0 false 0uy +createDecimal 0 1000000000 0 false 0uy +createDecimal 0 0 1000000000 false 0uy +createDecimal 1000000000 1000000000 1000000000 false 0uy +createDecimal -1 -1 -1 false 0uy +createDecimal -1 -1 -1 true 0uy +createDecimal -1 -1 -1 false 15uy +createDecimal -1 -1 -1 false 28uy +createDecimal -1 -1 -1 false 29uy +createDecimal Int32.MaxValue 0 0 false 18uy +createDecimal Int32.MaxValue 0 0 false 28uy +createDecimal Int32.MaxValue 0 0 true 28uy + + +// This example of the decimal(int, int, int, bool, byte) +// constructor generates the following output. +// +// Constructor Value or Exception +// ----------- ------------------ +// decimal( 0, 0, 0, False, 0 ) 0 +// decimal( 0, 0, 0, False, 27 ) 0 +// decimal( 0, 0, 0, True, 0 ) 0 +// decimal( 1000000000, 0, 0, False, 0 ) 1000000000 +// decimal( 0, 1000000000, 0, False, 0 ) 4294967296000000000 +// decimal( 0, 0, 1000000000, False, 0 ) 18446744073709551616000000000 +// decimal( 1000000000, 1000000000, 1000000000, False, 0 ) +// 18446744078004518913000000000 +// decimal( -1, -1, -1, False, 0 ) 79228162514264337593543950335 +// decimal( -1, -1, -1, True, 0 ) -79228162514264337593543950335 +// decimal( -1, -1, -1, False, 15 ) 79228162514264.337593543950335 +// decimal( -1, -1, -1, False, 28 ) 7.9228162514264337593543950335 +// decimal( -1, -1, -1, False, 29 ) ArgumentOutOfRangeException +// decimal( 2147483647, 0, 0, False, 18 ) 0.000000002147483647 +// decimal( 2147483647, 0, 0, False, 28 ) 0.0000000000000000002147483647 +// decimal( 2147483647, 0, 0, True, 28 ) -0.0000000000000000002147483647 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctorl.fs b/snippets/fsharp/System/Decimal/.ctor/ctorl.fs new file mode 100644 index 00000000000..d61a03974ef --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctorl.fs @@ -0,0 +1,40 @@ +module ctorl + +// +// Example of the decimal( int64 ) constructor. +open System + +// Create a decimal object and display its value. +let createDecimal (value: int64) valToStr = + let decimalNum = Decimal value + + // Format the constructor for display. + let ctor = $"decimal( {valToStr} )" + + // Display the constructor and its value. + printfn $"{ctor,-35}{decimalNum,22}" + +printfn "This example of the decimal( int64 ) constructor\ngenerates the following output.\n" +printfn "%-35s%22s" "Constructor" "Value" +printfn "%-35s%22s" "-----------" "-----" + +// Construct decimal objects from long values. +createDecimal Int64.MinValue "Int64.MinValue" +createDecimal Int64.MaxValue "Int64.MaxValue" +createDecimal 0L "0L" +createDecimal 999999999999999999L "999999999999999999L" +createDecimal 0x2000000000000000L "0x2000000000000000L" +createDecimal (int64 0xE000000000000000L) "int64 0xE000000000000000L" + +// This example of the decimal( int64 ) constructor +// generates the following output. +// +// Constructor Value +// ----------- ----- +// decimal( Int64.MinValue ) -9223372036854775808 +// decimal( Int64.MaxValue ) 9223372036854775807 +// decimal( 0L ) 0 +// decimal( 999999999999999999L ) 999999999999999999 +// decimal( 0x2000000000000000L ) 2305843009213693952 +// decimal( int64 0xE000000000000000L ) -2305843009213693952 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctors.fs b/snippets/fsharp/System/Decimal/.ctor/ctors.fs new file mode 100644 index 00000000000..be8cf441754 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctors.fs @@ -0,0 +1,58 @@ +module ctors + +// +// Example of the decimal( float ) constructor. +open System + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Create a decimal object and display its value. +let createDecimal (value: float32) valToStr = + // Format and display the constructor. + printf "%-27s" $"decimal( {valToStr} )" + + try + // Construct the decimal value. + let decimalNum = Decimal value + + // Display the value if it was created successfully. + printfn $"{decimalNum,31}" + with ex -> + // Display the exception type if an exception was thrown. + printfn $"{getExceptionType ex,31}" + + +printfn "This example of the decimal( float ) constructor \ngenerates the following output.\n" +printfn $"""{"Constructor",-27}{"Value or Exception",31}""" +printfn $"""{"-----------",-27}{"------------------",31}""" + +// Construct decimal objects from float values. +createDecimal 1.2345E+5f "1.2345E+5F" +createDecimal 1.234567E+15f "1.234567E+15F" +createDecimal 1.23456789E+25f "1.23456789E+25F" +createDecimal 1.23456789E+35f "1.23456789E+35F" +createDecimal 1.2345E-5f "1.2345E-5F" +createDecimal 1.234567E-15f "1.234567E-15F" +createDecimal 1.23456789E-25f "1.23456789E-25F" +createDecimal 1.23456789E-35f "1.23456789E-35F" +createDecimal (1f / 7f) "1.0F / 7.0F" + + +// This example of the decimal( float ) constructor +// generates the following output. + +// Constructor Value or Exception +// ----------- ------------------ +// decimal( 1.2345E+5F ) 123450 +// decimal( 1.234567E+15F ) 1234567000000000 +// decimal( 1.23456789E+25F ) 12345680000000000000000000 +// decimal( 1.23456789E+35F ) OverflowException +// decimal( 1.2345E-5F ) 0.000012345 +// decimal( 1.234567E-15F ) 0.000000000000001234567 +// decimal( 1.23456789E-25F ) 0.0000000000000000000000001235 +// decimal( 1.23456789E-35F ) 0 +// decimal( 1.0F / 7.0F ) 0.1428571 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctorui.fs b/snippets/fsharp/System/Decimal/.ctor/ctorui.fs new file mode 100644 index 00000000000..1aa5ea0a09f --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctorui.fs @@ -0,0 +1,41 @@ +module ctorui + +// +// Example of the decimal( uint ) constructor. +open System + +// Create a decimal object and display its value. +let createDecimal (value: uint) valToStr = + let decimalNum = Decimal value + + // Format the constructor for display. + let ctor = $"decimal( {valToStr} )" + + // Display the constructor and its value. + printfn $"{ctor,-33}{decimalNum,16}" + +printfn "This example of the decimal( uint ) constructor \ngenerates the following output.\n" +printfn "%-33s%16s" "Constructor" "Value" +printfn "%-33s%16s" "-----------" "-----" + +// Construct decimal objects from uint values. +createDecimal UInt32.MinValue "UInt32.MinValue" +createDecimal UInt32.MaxValue "UInt32.MaxValue" +createDecimal (uint Int32.MaxValue) "uint Int32.MaxValue" +createDecimal 999999999u "999999999u" +createDecimal 0x40000000u "0x40000000u" +createDecimal 0xC0000000u "0xC0000000u" + + +// This example of the decimal( uint ) constructor +// generates the following output. +// +// Constructor Value +// ----------- ----- +// decimal( UInt32.MinValue ) 0 +// decimal( UInt32.MaxValue ) 4294967295 +// decimal( uint Int32.MaxValue ) 2147483647 +// decimal( 999999999u ) 999999999 +// decimal( 0x40000000u ) 1073741824 +// decimal( 0xC0000000u ) 3221225472 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/ctorul.fs b/snippets/fsharp/System/Decimal/.ctor/ctorul.fs new file mode 100644 index 00000000000..5e712f55496 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/ctorul.fs @@ -0,0 +1,41 @@ +module ctorul + +// +// Example of the decimal( uint64 ) constructor. +open System + +// Create a decimal object and display its value. +let createDecimal (value: uint64) valToStr = + let decimalNum = Decimal value + + // Format the constructor for display. + let ctor = $"decimal( {valToStr} )" + + // Display the constructor and its value. + printfn $"{ctor,-35}{decimalNum,22}" + +printfn "This example of the decimal( uint64 ) constructor \ngenerates the following output.\n" +printfn "%-35s%22s" "Constructor" "Value" +printfn "%-35s%22s" "-----------" "-----" + +// Construct decimal objects from ulong values. +createDecimal UInt64.MinValue "UInt64.MinValue" +createDecimal UInt64.MaxValue "UInt64.MaxValue" +createDecimal (uint64 Int64.MaxValue) "int64 Int64.MaxValue" +createDecimal 999999999999999999uL "999999999999999999uL" +createDecimal 0x2000000000000000uL "0x2000000000000000uL" +createDecimal 0xE000000000000000uL "0xE000000000000000uL" + + +// This example of the decimal( uint64 ) constructor +// generates the following output. +// +// Constructor Value +// ----------- ----- +// decimal( UInt64.MinValue ) 0 +// decimal( UInt64.MaxValue ) 18446744073709551615 +// decimal( int64 Int64.MaxValue ) 9223372036854775807 +// decimal( 999999999999999999uL ) 999999999999999999 +// decimal( 0x2000000000000000uL ) 2305843009213693952 +// decimal( 0xE000000000000000uL ) 16140901064495857664 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/.ctor/fs.fsproj b/snippets/fsharp/System/Decimal/.ctor/fs.fsproj new file mode 100644 index 00000000000..453d258c483 --- /dev/null +++ b/snippets/fsharp/System/Decimal/.ctor/fs.fsproj @@ -0,0 +1,17 @@ + + + Exe + net6.0 + + + + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Ceiling/ceiling1.fs b/snippets/fsharp/System/Decimal/Ceiling/ceiling1.fs new file mode 100644 index 00000000000..5bcd53bae21 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Ceiling/ceiling1.fs @@ -0,0 +1,24 @@ +// +open System + +let values = + [ 12.6m; 12.1m; 9.5m; 8.16m; 0.1m; -0.1m; -1.1m; -1.9m; -3.9m ] + +printfn "%-8s %10s %10s\n" "Value" "Ceiling" "Floor" + +for value in values do + printfn $"%-8O{value} %10O{Decimal.Ceiling value} %10O{Decimal.Floor value}" + +// The example displays the following output: +// Value Ceiling Floor +// +// 12.6 13 12 +// 12.1 13 12 +// 9.5 10 9 +// 8.16 9 8 +// 0.1 1 0 +// -0.1 0 -1 +// -1.1 -1 -2 +// -1.9 -1 -2 +// -3.9 -3 -4 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Ceiling/fs.fsproj b/snippets/fsharp/System/Decimal/Ceiling/fs.fsproj new file mode 100644 index 00000000000..e410d2fc902 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Ceiling/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Compare/Compare1.fs b/snippets/fsharp/System/Decimal/Compare/Compare1.fs new file mode 100644 index 00000000000..14cdcc11c18 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Compare/Compare1.fs @@ -0,0 +1,29 @@ +// +open System + +type Relationship = + | LessThan = -1 + | Equals = 0 + | GreaterThan = 1 + +[] +let main _ = + let value1 = Decimal.MaxValue + let value2 = value1 - 0.01m + printfn $"{value1} {Decimal.Compare(value1, value2) |> enum} {value2}" + + let value2 = value1 / 12m - 0.1m + let value1 = value1 / 12m + printfn $"{value1} {Decimal.Compare(value1, value2) |> enum} {value2}" + + let value1 = value1 - 0.2m + let value2 = value2 + 0.1m + printfn $"{value1} {Decimal.Compare(value1, value2) |> enum} {value2}" + + 0 + +// The example displays the following output: +// 79228162514264337593543950335 Equals 79228162514264337593543950335 +// 6602346876188694799461995861.2 GreaterThan 6602346876188694799461995861.1 +// 6602346876188694799461995861.0 LessThan 6602346876188694799461995861.2 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Compare/fs.fsproj b/snippets/fsharp/System/Decimal/Compare/fs.fsproj new file mode 100644 index 00000000000..65ed4b65243 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Compare/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/CompareTo/comp_equal.fs b/snippets/fsharp/System/Decimal/CompareTo/comp_equal.fs new file mode 100644 index 00000000000..f3957678347 --- /dev/null +++ b/snippets/fsharp/System/Decimal/CompareTo/comp_equal.fs @@ -0,0 +1,62 @@ +module comp_equal + +// +// Example of the decimal.Compare and static decimal.Equals methods. +open System + +let print message obj = printfn $"%-45s{message}{obj}" + +// Compare decimal parameters, and display them with the results. +let compareDecimals (left: decimal) (right: decimal) (rightText: string) = + printfn "" + print $"right: {rightText}" right + print "decimal.Equals(left, right) " (Decimal.Equals(left, right)) + print "decimal.Compare(left, right) " (Decimal.Compare(left, right)) + +Console.WriteLine( "This example of the " + + "decimal.Equals(decimal, decimal) and \n" + + "decimal.Compare(decimal, decimal) methods " + + "generates the \nfollowing output. It creates several " + + "different decimal \nvalues and compares them with " + + "the following reference value.\n" ) + +// Create a reference decimal value. +let left = decimal 123.456 + +print "left: decimal( 123.456 )" left + +// Create decimal values to compare with the reference. +compareDecimals left (decimal 1.2345600E+2 ) "decimal(1.2345600E+2)" +compareDecimals left 123.4561M "123.4561M" +compareDecimals left 123.4559M "123.4559M" +compareDecimals left 123.456000M "123.456000M" +compareDecimals left (Decimal(123456000, 0, 0, false, 6uy)) "Decimal(123456000, 0, 0, false, 6)" + + +// This example of the decimal.Equals(decimal, decimal) and +// decimal.Compare(decimal, decimal) methods generates the +// following output. It creates several different decimal +// values and compares them with the following reference value. + +// left: decimal(123.456) 123.456 + +// right: decimal(1.2345600E+2) 123.456 +// decimal.Equals(left, right) True +// decimal.Compare(left, right) 0 + +// right: 123.4561M 123.4561 +// decimal.Equals(left, right) False +// decimal.Compare(left, right) -1 + +// right: 123.4559M 123.4559 +// decimal.Equals(left, right) False +// decimal.Compare(left, right) 1 + +// right: 123.456000M 123.456000 +// decimal.Equals(left, right) True +// decimal.Compare(left, right) 0 + +// right: decimal(123456000, 0, 0, false, 6) 123.456000 +// decimal.Equals(left, right) True +// decimal.Compare(left, right) 0 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/CompareTo/cto_eq_obj.fs b/snippets/fsharp/System/Decimal/CompareTo/cto_eq_obj.fs new file mode 100644 index 00000000000..067f6cced9a --- /dev/null +++ b/snippets/fsharp/System/Decimal/CompareTo/cto_eq_obj.fs @@ -0,0 +1,76 @@ +module cto_eq_obj + +// +// Example of the decimal.CompareTo and decimal.Equals instance +// methods. +open System + +// Get the exception type name remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Compare the decimal to the object parameters, +// and display the object parameters with the results. +let compDecimalToObject (left: decimal) (right: obj) (rightText: string) = + printfn $"object: %-38s{rightText}{right}" + printfn $"""%-46s{"left.Equals(object)"}{left.Equals right}""" + printf $"""%-46s{"left.CompareTo(object)"}""" + + try + // Catch the exception if CompareTo( ) throws one. + printfn $"{left.CompareTo right}\n" + with ex -> + printfn $"{getExceptionType ex}\n" + +Console.WriteLine( + "This example of the decimal.Equals( object ) and \n" + + "decimal.CompareTo( object ) methods generates the \n" + + "following output. It creates several different " + + "decimal \nvalues and compares them with the following " + + "reference value.\n" ) + +// Create a reference decimal value. +let left = decimal 987.654 + +printfn $"""{"Left: decimal(987.654)",-46}{left}\n""" + +// Create objects to compare with the reference. +compDecimalToObject left (decimal 9.8765400E+2 ) "decimal(9.8765400E+2)" +compDecimalToObject left 987.6541M "987.6541D" +compDecimalToObject left 987.6539M "987.6539D" +compDecimalToObject left (Decimal(987654000, 0, 0, false, 6uy)) "Decimal(987654000, 0, 0, false, 6)" +compDecimalToObject left 9.8765400E+2 "Double 9.8765400E+2" +compDecimalToObject left "987.654" "String \"987.654\"" + + +// This example of the Decimal.Equals(object) and +// Decimal.CompareTo(object) methods generates the +// following output. It creates several different decimal +// values and compares them with the following reference value. +// Left: decimal(987.654) 987.654 +// +// object: decimal(9.8765400E+2) 987.654 +// left.Equals(object) True +// left.CompareTo(object) 0 +// +// object: 987.6541D 987.6541 +// left.Equals(object) False +// left.CompareTo(object) -1 +// +// object: 987.6539D 987.6539 +// left.Equals(object) False +// left.CompareTo(object) 1 +// +// object: Decimal(987654000, 0, 0, false, 6) 987.654000 +// left.Equals(object) True +// left.CompareTo(object) 0 +// +// object: Double 9.8765400E+2 987.654 +// left.Equals(object) False +// left.CompareTo(object) ArgumentException +// +// object: String "987.654" 987.654 +// left.Equals(object) False +// left.CompareTo(object) ArgumentException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/CompareTo/fs.fsproj b/snippets/fsharp/System/Decimal/CompareTo/fs.fsproj new file mode 100644 index 00000000000..c301fdd8f8b --- /dev/null +++ b/snippets/fsharp/System/Decimal/CompareTo/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Divide/Divide1.fs b/snippets/fsharp/System/Decimal/Divide/Divide1.fs new file mode 100644 index 00000000000..ceab2a53465 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Divide/Divide1.fs @@ -0,0 +1,22 @@ +// +open System + +// Divide a series of numbers by 22.1 +let dividend = 1230.0m +let divisor = 22.1m +for i = 0 to 10 do + printfn $"{dividend:N1} / {divisor:N1} = {Decimal.Divide(dividend + (decimal i) * 0.1m, divisor):N4}" + +// The example displays the following output: +// 1,230.0 / 22.1 = 55.6561 +// 1,230.1 / 22.1 = 55.6606 +// 1,230.2 / 22.1 = 55.6652 +// 1,230.3 / 22.1 = 55.6697 +// 1,230.4 / 22.1 = 55.6742 +// 1,230.5 / 22.1 = 55.6787 +// 1,230.6 / 22.1 = 55.6833 +// 1,230.7 / 22.1 = 55.6878 +// 1,230.8 / 22.1 = 55.6923 +// 1,230.9 / 22.1 = 55.6968 +// 1,231.0 / 22.1 = 55.7014 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Divide/fs.fsproj b/snippets/fsharp/System/Decimal/Divide/fs.fsproj new file mode 100644 index 00000000000..eed21366d8b --- /dev/null +++ b/snippets/fsharp/System/Decimal/Divide/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs b/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs new file mode 100644 index 00000000000..dcb2ff947d2 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs @@ -0,0 +1,78 @@ +// +let value = 112m + +let testObjectForEquality (obj: obj) = + printfn $"{value} ({value.GetType().Name}) = {obj} ({obj.GetType().Name}): {value.Equals obj}\n" + +let byte1 = 112uy +printfn $"value = byte1: {value.Equals byte1,17}" +testObjectForEquality byte1 + +let short1 = 112s +printfn $"value = short1: {value.Equals short1,17}" +testObjectForEquality short1 + +let int1 = 112 +printfn $"value = int1: {value.Equals int1,19}" +testObjectForEquality int1 + +let long1 = 112L +printfn $"value = long1: {value.Equals long1,18}" +testObjectForEquality long1 + +let sbyte1 = 112y +printfn $"value = sbyte1: {value.Equals sbyte1,17}" +testObjectForEquality sbyte1 + +let ushort1 = 112us +printfn $"value = ushort1: {value.Equals ushort1,17}" +testObjectForEquality ushort1 + +let uint1 = 112u +printfn $"value = uint1: {value.Equals uint1,19}" +testObjectForEquality uint1 + +let ulong1 = 112uL +printfn $"value = ulong1: {value.Equals ulong1,18}" +testObjectForEquality ulong1 + +let sng1 = 112f +printfn $"value = sng1: {value.Equals sng1,21}" +testObjectForEquality sng1 + +let dbl1 = 112. +printfn $"value = dbl1: {value.Equals dbl1,21}" +testObjectForEquality dbl1 + + +// The example displays the following output: +// value = byte1: True +// 112 (Decimal) = 112 (Byte): False +// +// value = short1: True +// 112 (Decimal) = 112 (Int16): False +// +// value = int1: True +// 112 (Decimal) = 112 (Int32): False +// +// value = long1: True +// 112 (Decimal) = 112 (Int64): False +// +// value = sbyte1: True +// 112 (Decimal) = 112 (SByte): False +// +// value = ushort1: True +// 112 (Decimal) = 112 (UInt16): False +// +// value = uint1: True +// 112 (Decimal) = 112 (UInt32): False +// +// value = ulong1: True +// 112 (Decimal) = 112 (UInt64): False +// +// value = sng1: False +// 112 (Decimal) = 112 (Single): False +// +// value = dbl1: False +// 112 (Decimal) = 112 (Double): False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Equals/fs.fsproj b/snippets/fsharp/System/Decimal/Equals/fs.fsproj new file mode 100644 index 00000000000..f1da800c5f5 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Equals/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/FromOACurrency/fromoacurrency.fs b/snippets/fsharp/System/Decimal/FromOACurrency/fromoacurrency.fs new file mode 100644 index 00000000000..ba8c1c80173 --- /dev/null +++ b/snippets/fsharp/System/Decimal/FromOACurrency/fromoacurrency.fs @@ -0,0 +1,56 @@ +module fromoacurrency + +// +// Example of the Decimal.FromOACurrency method. +open System + +let dataFmt obj1 obj2 = printfn $"{obj1,21}{obj2,25}" + +// Display the Decimal.FromOACurrency parameter and decimal result. +let showDecimalFromOACurrency argument = + let decCurrency = Decimal.FromOACurrency argument + + dataFmt argument decCurrency + +printfn + """This example of the Decimal.FromOACurrency() method generates +the following output. It displays the OLE Automation Currency +value as a long and the result as a decimal. +""" +dataFmt "OA Currency" "Decimal Value" +dataFmt "-----------" "-------------" + +// Convert OLE Automation Currency values to decimal objects. +showDecimalFromOACurrency 0L +showDecimalFromOACurrency 1L +showDecimalFromOACurrency 100000L +showDecimalFromOACurrency 100000000000L +showDecimalFromOACurrency 1000000000000000000L +showDecimalFromOACurrency 1000000000000000001L +showDecimalFromOACurrency Int64.MaxValue +showDecimalFromOACurrency Int64.MinValue +showDecimalFromOACurrency 123456789L +showDecimalFromOACurrency 1234567890000L +showDecimalFromOACurrency 1234567890987654321L +showDecimalFromOACurrency 4294967295L + + +// This example of the Decimal.FromOACurrency() method generates +// the following output. It displays the OLE Automation Currency +// value as a long and the result as a decimal. + +// OA Currency Decimal Value +// ----------- ------------- +// 0 0 +// 1 0.0001 +// 100000 10 +// 100000000000 10000000 +// 1000000000000000000 100000000000000 +// 1000000000000000001 100000000000000.0001 +// 9223372036854775807 922337203685477.5807 +// -9223372036854775808 -922337203685477.5808 +// 123456789 12345.6789 +// 1234567890000 123456789 +// 1234567890987654321 123456789098765.4321 +// 4294967295 429496.7295 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/FromOACurrency/fs.fsproj b/snippets/fsharp/System/Decimal/FromOACurrency/fs.fsproj new file mode 100644 index 00000000000..c556a0ae0f1 --- /dev/null +++ b/snippets/fsharp/System/Decimal/FromOACurrency/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/FromOACurrency/tooacurrency.fs b/snippets/fsharp/System/Decimal/FromOACurrency/tooacurrency.fs new file mode 100644 index 00000000000..90a0778b67e --- /dev/null +++ b/snippets/fsharp/System/Decimal/FromOACurrency/tooacurrency.fs @@ -0,0 +1,69 @@ +module tooacurrency + +// +// Example of the Decimal.ToOACurrency method. +open System + +let dataFmt obj1 obj2 = printfn $"{obj1,31}{obj2,27}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Display the Decimal.ToOACurrency parameter and the result +// or exception. +let showDecimalToOACurrency argument = + // Catch the exception if ToOACurrency( ) throws one. + try + let oaCurrency = Decimal.ToOACurrency argument + dataFmt argument oaCurrency + with ex -> + dataFmt argument (getExceptionType ex) + +printfn + """This example of the Decimal.ToOACurrency() method generates +the following output. It displays the argument as a decimal +and the OLE Automation Currency value as a long. +""" +dataFmt "Argument" "OA Currency or Exception" +dataFmt "--------" "------------------------" + +// Convert decimal values to OLE Automation Currency values. +showDecimalToOACurrency 0M +showDecimalToOACurrency 1M +showDecimalToOACurrency 1.0000000000000000000000000000M +showDecimalToOACurrency 100000000000000M +showDecimalToOACurrency 100000000000000.00000000000000M +showDecimalToOACurrency 10000000000000000000000000000M +showDecimalToOACurrency 0.000000000123456789M +showDecimalToOACurrency 0.123456789M +showDecimalToOACurrency 123456789M +showDecimalToOACurrency 123456789000000000M +showDecimalToOACurrency 4294967295M +showDecimalToOACurrency 18446744073709551615M +showDecimalToOACurrency -79.228162514264337593543950335M +showDecimalToOACurrency -79228162514264.337593543950335M + + +// This example of the Decimal.ToOACurrency() method generates +// the following output. It displays the argument as a decimal +// and the OLE Automation Currency value as a long. +// +// Argument OA Currency or Exception +// -------- ------------------------ +// 0 0 +// 1 10000 +// 1.0000000000000000000000000000 10000 +// 100000000000000 1000000000000000000 +// 100000000000000.00000000000000 1000000000000000000 +// 10000000000000000000000000000 OverflowException +// 0.000000000123456789 0 +// 0.123456789 1235 +// 123456789 1234567890000 +// 123456789000000000 OverflowException +// 4294967295 42949672950000 +// 18446744073709551615 OverflowException +// -79.228162514264337593543950335 -792282 +// -79228162514264.337593543950335 -792281625142643376 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/GetBits/fs.fsproj b/snippets/fsharp/System/Decimal/GetBits/fs.fsproj new file mode 100644 index 00000000000..48ab7b2078a --- /dev/null +++ b/snippets/fsharp/System/Decimal/GetBits/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/GetBits/getbits.fs b/snippets/fsharp/System/Decimal/GetBits/getbits.fs new file mode 100644 index 00000000000..3528c0715fc --- /dev/null +++ b/snippets/fsharp/System/Decimal/GetBits/getbits.fs @@ -0,0 +1,41 @@ +module getbits + +// +open System + +// Define an list of Decimal values. +let values = + [ 1M; 100000000000000M; 10000000000000000000000000000M + 100000000000000.00000000000000M; 1.0000000000000000000000000000M + 123456789M; 0.123456789M; 0.000000000123456789M + 0.000000000000000000123456789M; 4294967295M + 18446744073709551615M; Decimal.MaxValue + Decimal.MinValue; -7.9228162514264337593543950335M ] + +printfn $"""{"Argument",31} {"Bits[3]",10:X8}{"Bits[2]",10:X8}{"Bits[1]",10:X8}{"Bits[0]",10:X8}""" +printfn $"""{"--------",31} {"-------",10:X8}{"-------",10:X8}{"-------",10:X8}{"-------",10:X8}""" + +// Iterate each element and display its binary representation +for value in values do + let bits = Decimal.GetBits value + printfn $"{value,31} {bits[3],10:X8}{bits[2],10:X8}{bits[1],10:X8}{bits[0],10:X8}" + + +// The example displays the following output: +// Argument Bits[3] Bits[2] Bits[1] Bits[0] +// -------- ------- ------- ------- ------- +// 1 00000000 00000000 00000000 00000001 +// 100000000000000 00000000 00000000 00005AF3 107A4000 +// 10000000000000000000000000000 00000000 204FCE5E 3E250261 10000000 +// 100000000000000.00000000000000 000E0000 204FCE5E 3E250261 10000000 +// 1.0000000000000000000000000000 001C0000 204FCE5E 3E250261 10000000 +// 123456789 00000000 00000000 00000000 075BCD15 +// 0.123456789 00090000 00000000 00000000 075BCD15 +// 0.000000000123456789 00120000 00000000 00000000 075BCD15 +// 0.000000000000000000123456789 001B0000 00000000 00000000 075BCD15 +// 4294967295 00000000 00000000 00000000 FFFFFFFF +// 18446744073709551615 00000000 00000000 FFFFFFFF FFFFFFFF +// 79228162514264337593543950335 00000000 FFFFFFFF FFFFFFFF FFFFFFFF +// -79228162514264337593543950335 80000000 FFFFFFFF FFFFFFFF FFFFFFFF +// -7.9228162514264337593543950335 801C0000 FFFFFFFF FFFFFFFF FFFFFFFF +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/GetBits/gettypecode.fs b/snippets/fsharp/System/Decimal/GetBits/gettypecode.fs new file mode 100644 index 00000000000..c81f1bd4c7e --- /dev/null +++ b/snippets/fsharp/System/Decimal/GetBits/gettypecode.fs @@ -0,0 +1,22 @@ +module gettypecode + +// +// Example of the Decimal.GetTypeCode method. +open System + +printfn $"This example of the decimal.GetTypeCode() \nmethod generates the following output.\n" + +// Create a decimal object and get its type code. +let aDecimal = Decimal 1.0 +let typCode = aDecimal.GetTypeCode() + +printfn $"Type Code: \"{typCode}\"" +printfn $"Numeric value: {int typCode}" + + +// This example of the decimal.GetTypeCode() +// method generates the following output. +// +// Type Code: "Decimal" +// Numeric value: 15 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/MinusOne/fields.fs b/snippets/fsharp/System/Decimal/MinusOne/fields.fs new file mode 100644 index 00000000000..cb23570eca2 --- /dev/null +++ b/snippets/fsharp/System/Decimal/MinusOne/fields.fs @@ -0,0 +1,42 @@ +// +// Example of the Decimal fields. +open System + +let numberFmt obj1 obj2 = printfn $"{obj1,-25}{obj2,45:N0}" +let exprFmt obj1 obj2 = printfn $"{obj1,-55}{obj2,15}" + +printfn "This example of the fields of the Decimal structure \ngenerates the following output.\n" +numberFmt "Field or Expression" "Value" +numberFmt "-------------------" "-----" + +// Display the values of the Decimal fields. +numberFmt "Decimal.MaxValue" Decimal.MaxValue +numberFmt "Decimal.MinValue" Decimal.MinValue +numberFmt "Decimal.MinusOne" Decimal.MinusOne +numberFmt "Decimal.One" Decimal.One +numberFmt "Decimal.Zero" Decimal.Zero +printfn "" + +// Display the values of expressions of the Decimal fields. +exprFmt "( Decimal.MinusOne + Decimal.One ) == Decimal.Zero" (Decimal.MinusOne + Decimal.One = Decimal.Zero) +exprFmt "Decimal.MaxValue + Decimal.MinValue" (Decimal.MaxValue + Decimal.MinValue) +exprFmt "Decimal.MinValue / Decimal.MaxValue" (Decimal.MinValue / Decimal.MaxValue) +printfn "%-40s%30O" "100000000000000M / Decimal.MaxValue" (100000000000000M / Decimal.MaxValue) + + +// This example of the fields of the Decimal structure +// generates the following output. +// +// Field or Expression Value +// ------------------- ----- +// Decimal.MaxValue 79,228,162,514,264,337,593,543,950,335 +// Decimal.MinValue -79,228,162,514,264,337,593,543,950,335 +// Decimal.MinusOne -1 +// Decimal.One 1 +// Decimal.Zero 0 +// +// ( Decimal.MinusOne + Decimal.One ) == Decimal.Zero True +// Decimal.MaxValue + Decimal.MinValue 0 +// Decimal.MinValue / Decimal.MaxValue -1 +// 100000000000000M / Decimal.MaxValue 0.0000000000000012621774483536 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/MinusOne/fs.fsproj b/snippets/fsharp/System/Decimal/MinusOne/fs.fsproj new file mode 100644 index 00000000000..6b29410faca --- /dev/null +++ b/snippets/fsharp/System/Decimal/MinusOne/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Multiply/fs.fsproj b/snippets/fsharp/System/Decimal/Multiply/fs.fsproj new file mode 100644 index 00000000000..ebba121bb00 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Multiply/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Multiply/mul_div_rem.fs b/snippets/fsharp/System/Decimal/Multiply/mul_div_rem.fs new file mode 100644 index 00000000000..c17df084113 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Multiply/mul_div_rem.fs @@ -0,0 +1,71 @@ +// +// Example of the Decimal.Multiply, Decimal.Divide, and +// Decimal.Remainder methods. +open System + +let dataFmt obj1 obj2 = printfn $"{obj1,-35}{obj2,31}" + +// Display decimal parameters and their product, quotient, and remainder. +let showDecimalProQuoRem left right = + printfn "" + dataFmt "decimal left" left + dataFmt "decimal right" right + dataFmt "Decimal.Multiply( left, right )" (Decimal.Multiply(left, right)) + dataFmt "Decimal.Divide( left, right )" (Decimal.Divide(left, right)) + dataFmt "Decimal.Remainder( left, right )" (Decimal.Remainder(left, right)) + +printfn + """This example of the + Decimal.Multiply( decimal, decimal ), + Decimal.Divide( decimal, decimal ), and + Decimal.Remainder( decimal, decimal ) +methods generates the following output. It displays +the product, \nquotient, and remainder of several +pairs of decimal objects.""" + +// Create pairs of decimal objects. +showDecimalProQuoRem 1000M 7M +showDecimalProQuoRem -1000M 7M +showDecimalProQuoRem (Decimal(1230000000, 0, 0, false, 7uy)) 0.0012300M +showDecimalProQuoRem 12345678900000000M 0.0000000012345678M +showDecimalProQuoRem 123456789.0123456789M 123456789.1123456789M + + +// This example of the +// Decimal.Multiply( decimal, decimal ), +// Decimal.Divide( decimal, decimal ), and +// Decimal.Remainder( decimal, decimal ) +// methods generates the following output. It displays +// the product, \nquotient, and remainder of several +// pairs of decimal objects. +// +// decimal left 1000 +// decimal right 7 +// Decimal.Multiply( left, right ) 7000 +// Decimal.Divide( left, right ) 142.85714285714285714285714286 +// Decimal.Remainder( left, right ) 6 +// +// decimal left -1000 +// decimal right 7 +// Decimal.Multiply( left, right ) -7000 +// Decimal.Divide( left, right ) -142.85714285714285714285714286 +// Decimal.Remainder( left, right ) -6 +// +// decimal left 123.0000000 +// decimal right 0.0012300 +// Decimal.Multiply( left, right ) 0.15129000000000 +// Decimal.Divide( left, right ) 100000 +// Decimal.Remainder( left, right ) 0.0000000 +// +// decimal left 12345678900000000 +// decimal right 0.0000000012345678 +// Decimal.Multiply( left, right ) 15241577.6390794200000000 +// Decimal.Divide( left, right ) 10000000729000059778004901.796 +// Decimal.Remainder( left, right ) 0.0000000009832122 +// +// decimal left 123456789.0123456789 +// decimal right 123456789.1123456789 +// Decimal.Multiply( left, right ) 15241578765584515.651425087878 +// Decimal.Divide( left, right ) 0.9999999991899999933660999449 +// Decimal.Remainder( left, right ) 123456789.0123456789 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Negate/floor_neg_trunc.fs b/snippets/fsharp/System/Decimal/Negate/floor_neg_trunc.fs new file mode 100644 index 00000000000..4f6d530418d --- /dev/null +++ b/snippets/fsharp/System/Decimal/Negate/floor_neg_trunc.fs @@ -0,0 +1,61 @@ +// +// Example of the decimal.Negate, decimal.Floor, and decimal.Truncate +// methods. +open System + +let dataFmt obj1 obj2 = printfn $"{obj1,-30}{obj2,26}" + +// Display decimal parameters and the method results. +let showDecimalFloorNegTrunc (argument: decimal) = + printfn "" + dataFmt "decimal argument" argument + dataFmt "Decimal.Negate( argument )" (Decimal.Negate argument) + dataFmt "decimal.Floor( argument )" (Decimal.Floor argument) + dataFmt "decimal.Truncate( argument )" (Decimal.Truncate argument) + +printfn + """This example of the + decimal.Negate( decimal ), + decimal.Floor( decimal ), and + decimal.Truncate( decimal ) +methods generates the following output.""" + +// Create pairs of decimal objects. +showDecimalFloorNegTrunc 0M +showDecimalFloorNegTrunc 123.456M +showDecimalFloorNegTrunc -123.456M +showDecimalFloorNegTrunc (Decimal(1230000000, 0, 0, true, 7uy)) +showDecimalFloorNegTrunc -9999999999.9999999999M + + +// This example of the +// decimal.Negate( decimal ), +// decimal.Floor( decimal ), and +// decimal.Truncate( decimal ) +// methods generates the following output. +// +// decimal argument 0 +// Decimal.Negate( argument ) 0 +// decimal.Floor( argument ) 0 +// decimal.Truncate( argument ) 0 +// +// decimal argument 123.456 +// Decimal.Negate( argument ) -123.456 +// decimal.Floor( argument ) 123 +// decimal.Truncate( argument ) 123 +// +// decimal argument -123.456 +// Decimal.Negate( argument ) 123.456 +// decimal.Floor( argument ) -124 +// decimal.Truncate( argument ) -123 +// +// decimal argument -123.0000000 +// Decimal.Negate( argument ) 123.0000000 +// decimal.Floor( argument ) -123 +// decimal.Truncate( argument ) -123 +// +// decimal argument -9999999999.9999999999 +// Decimal.Negate( argument ) 9999999999.9999999999 +// decimal.Floor( argument ) -10000000000 +// decimal.Truncate( argument ) -9999999999 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Negate/fs.fsproj b/snippets/fsharp/System/Decimal/Negate/fs.fsproj new file mode 100644 index 00000000000..8ceb919174a --- /dev/null +++ b/snippets/fsharp/System/Decimal/Negate/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Overview/DecimalDivision_46630_1.fs b/snippets/fsharp/System/Decimal/Overview/DecimalDivision_46630_1.fs new file mode 100644 index 00000000000..8c95a3d5e51 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Overview/DecimalDivision_46630_1.fs @@ -0,0 +1,22 @@ +module DecimalDivision_46630_1 + +open System + +let divideWithoutRounding () = + // + let dividend = Decimal.One + let divisor = 3m + // The following displays 0.9999999999999999999999999999 to the console + printfn $"{dividend/divisor * divisor}" + // + +let divideWithRounding () = + // + let dividend = Decimal.One + let divisor = 3m + // The following displays 1.00 to the console + printfn $"{Math.Round(dividend/divisor * divisor, 2)}" + // + +divideWithoutRounding () +divideWithRounding () \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Overview/fs.fsproj b/snippets/fsharp/System/Decimal/Overview/fs.fsproj new file mode 100644 index 00000000000..ed7024dea75 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Overview/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Overview/source.fs b/snippets/fsharp/System/Decimal/Overview/source.fs new file mode 100644 index 00000000000..105f475288e --- /dev/null +++ b/snippets/fsharp/System/Decimal/Overview/source.fs @@ -0,0 +1,73 @@ +module snippets + +open System + +module snippet1 = + // + /// Keeping my fortune in Decimals to avoid the round-off errors. + type PiggyBank() = + let mutable myFortune = 0m + + member _.AddPenny() = + myFortune <- Decimal.Add(myFortune, 0.01m) + + member _.Capacity = + Decimal.MaxValue + + member _.Dollars = + Decimal.Floor myFortune + + member _.Cents = + Decimal.Subtract(myFortune, Decimal.Floor myFortune) + + override _.ToString() = + $"{myFortune:C} in piggy bank" + // + +module snippet2 = + // + type PiggyBank() = + let mutable myFortune = 0m + + member _.Capacity = + Decimal.MaxValue + + member _.AddPenny() = + myFortune <- myFortune + 0.01m + // + +module snippet3 = + // + type PiggyBank() = + let mutable myFortune = 0m + + member _.Dollars = + Decimal.Floor myFortune + + member _.AddPenny() = + myFortune <- myFortune + 0.01m + // + +module snippet4 = + // + type PiggyBank() = + let mutable myFortune = 0m + + member _.Cents = + Decimal.Subtract(myFortune, Decimal.Floor myFortune) + + member _.AddPenny() = + myFortune <- myFortune + 0.01m + // + +module snippet5 = + // + type PiggyBank() = + let mutable myFortune = 0m + + member _.AddPenny() = + myFortune <- Decimal.Add(myFortune, 0.01m) + + override _.ToString() = + $"{myFortune:C} in piggy bank" + // \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Parse/fs.fsproj b/snippets/fsharp/System/Decimal/Parse/fs.fsproj new file mode 100644 index 00000000000..ef8721d8acf --- /dev/null +++ b/snippets/fsharp/System/Decimal/Parse/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Parse/parse.fs b/snippets/fsharp/System/Decimal/Parse/parse.fs new file mode 100644 index 00000000000..edba5511f75 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Parse/parse.fs @@ -0,0 +1,127 @@ +open System +open System.Globalization + +let callParse () = + // + // Parse an integer with thousands separators. + let value = "16,523,421" + let number = Decimal.Parse value + printfn $"'{value}' converted to {number}." + // Displays: + // '16,523,421' converted to 16523421. + + // Parse a floating point value with thousands separators + let value = "25,162.1378" + let number = Decimal.Parse value + printfn $"'{value}' converted to {number}." + // Displays: + // '25,162.1378' converted to 25162.1378. + + // Parse a floating point number with US currency symbol. + let value = "$16,321,421.75" + try + let number = Decimal.Parse value + printfn $"'{value}' converted to {number}." + with :? FormatException -> + printfn $"Unable to parse '{value}'." + // Displays: + // Unable to parse '$16,321,421.75'. + + // Parse a number in exponential notation + let value = "1.62345e-02" + try + let number = Decimal.Parse value + printfn $"'{value}' converted to {number}." + with :? FormatException -> + printfn $"Unable to parse '{value}'." + // Displays: + // Unable to parse '1.62345e-02'. + // + +let callParseWithStyles () = + // + // Parse string with a floating point value using NumberStyles.None. + let value = "8694.12" + let style = NumberStyles.None + try + let number = Decimal.Parse(value, style) + printfn $"'{value}' converted to {number}." + with :? FormatException -> + printfn $"Unable to parse '{value}'." + // Displays: + // Unable to parse '8694.12'. + + // Parse string with a floating point value and allow decimal point. + let style = NumberStyles.AllowDecimalPoint + let number = Decimal.Parse(value, style) + printfn $"'{value}' converted to {number}." + // Displays: + // '8694.12' converted to 8694.12. + + // Parse string with negative value in parentheses + let value = "(1,789.34)" + let style = + NumberStyles.AllowDecimalPoint ||| + NumberStyles.AllowThousands ||| + NumberStyles.AllowParentheses + let number = Decimal.Parse(value, style) + printfn $"'{value}' converted to {number}." + // Displays: + // '(1,789.34)' converted to -1789.34. + + // Parse string using Number style + let value = " -17,623.49 " + let style = NumberStyles.Number + let number = Decimal.Parse(value, style) + printfn $"'{value}' converted to {number}." + // Displays: + // ' -17,623.49 ' converted to -17623.49. + // + +let callParseWithStylesAndProvider () = + // + // Parse string using " " as the thousands separator + // and "," as the decimal separator for fr-FR culture. + let value = "892 694,12" + let style = NumberStyles.AllowDecimalPoint ||| NumberStyles.AllowThousands + let provider = CultureInfo "fr-FR" + + let number = Decimal.Parse(value, style, provider) + printfn $"'{value}' converted to {number}." + // Displays: + // '892 694,12' converted to 892694.12. + + try + let number = Decimal.Parse(value, style, CultureInfo.InvariantCulture) + printfn $"'{value}' converted to {number}." + with :? FormatException -> + printfn $"Unable to parse '{value}'." + // Displays: + // Unable to parse '892 694,12'. + + // Parse string using "$" as the currency symbol for en-GB and + // en-US cultures. + let value = "$6,032.51" + let style = NumberStyles.Number ||| NumberStyles.AllowCurrencySymbol + let provider = CultureInfo "en-GB" + + try + let number = Decimal.Parse(value, style, provider) + printfn $"'{value}' converted to {number}." + with :? FormatException -> + printfn $"Unable to parse '{value}'." + // Displays: + // Unable to parse '$6,032.51'. + + let provider = CultureInfo "en-US" + let number = Decimal.Parse(value, style, provider) + printfn $"'{value}' converted to {number}." + // Displays: + // '$6,032.51' converted to 6032.51. + // + +callParse () +printfn "-----" +callParseWithStyles () +printfn "-----" +callParseWithStylesAndProvider () \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Remainder/fs.fsproj b/snippets/fsharp/System/Decimal/Remainder/fs.fsproj new file mode 100644 index 00000000000..45e9c202c94 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Remainder/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Remainder/remainder.fs b/snippets/fsharp/System/Decimal/Remainder/remainder.fs new file mode 100644 index 00000000000..0bddb33c9ad --- /dev/null +++ b/snippets/fsharp/System/Decimal/Remainder/remainder.fs @@ -0,0 +1,22 @@ +// +open System + +// Create parallel lists of Decimals to use as the dividend and divisor. +let dividends = + [ 79m; 1000m; -1000m; 123m; 1234567800000m; 1234.0123m ] +let divisors = + [ 11m; 7m; 7m; 0.00123m; 0.12345678m; 1234.5678m ] + +for i = 0 to dividends.Length - 1 do + let dividend = dividends[i] + let divisor = divisors[i] + printfn $"{dividend:N3} / {divisor:N3} = {Decimal.Divide(dividend, divisor):N3} Remainder {Decimal.Remainder(dividend, divisor):N3}" + +// The example displays the following output: +// 79.000 / 11.000 = 7.182 Remainder 2.000 +// 1,000.000 / 7.000 = 142.857 Remainder 6.000 +// -1,000.000 / 7.000 = -142.857 Remainder -6.000 +// 123.000 / 0.001 = 100,000.000 Remainder 0.000 +// 1,234,567,800,000.000 / 0.123 = 10,000,000,000,000.000 Remainder 0.000 +// 1,234.012 / 1,234.568 = 1.000 Remainder 1,234.012 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Round/Round1.fs b/snippets/fsharp/System/Decimal/Round/Round1.fs new file mode 100644 index 00000000000..d1cf7b0fab3 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Round/Round1.fs @@ -0,0 +1,31 @@ +module Round1 + +// +open System + +for value in 100m .. 0.1m .. 102m do + printfn $"{value} --> {Decimal.Round value}" + +// The example displays the following output: +// 100 --> 100 +// 100.1 --> 100 +// 100.2 --> 100 +// 100.3 --> 100 +// 100.4 --> 100 +// 100.5 --> 100 +// 100.6 --> 101 +// 100.7 --> 101 +// 100.8 --> 101 +// 100.9 --> 101 +// 101.0 --> 101 +// 101.1 --> 101 +// 101.2 --> 101 +// 101.3 --> 101 +// 101.4 --> 101 +// 101.5 --> 102 +// 101.6 --> 102 +// 101.7 --> 102 +// 101.8 --> 102 +// 101.9 --> 102 +// 102.0 --> 102 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Round/Round12.fs b/snippets/fsharp/System/Decimal/Round/Round12.fs new file mode 100644 index 00000000000..6da4810326c --- /dev/null +++ b/snippets/fsharp/System/Decimal/Round/Round12.fs @@ -0,0 +1,38 @@ +module Round12 + +// +open System + +// Define a set of Decimal values. +let values = + [ 1.45m; 1.55m; 123.456789m; 123.456789m + 123.456789m; -123.456m + Decimal(1230000000, 0, 0, true, 7uy) + Decimal(1230000000, 0, 0, true, 7uy) + -9999999999.9999999999m + -9999999999.9999999999m ] + +// Define a set of integers to for decimals argument. +let decimals = + [ 1; 1; 4; 6; 8; 0; 3; 11; 9; 10 ] + +printfn $"""{"Argument",26}{"Digits",8}{"Result",26}""" +printfn $"""{"--------",26}{"------",8}{"------",26}""" + +for i = 0 to values.Length - 1 do + printfn $"{values[i],26}{decimals[i],8}{Decimal.Round(values[i], decimals[i]),26}" + +// The example displays the following output: +// Argument Digits Result +// -------- ------ ------ +// 1.45 1 1.4 +// 1.55 1 1.6 +// 123.456789 4 123.4568 +// 123.456789 6 123.456789 +// 123.456789 8 123.456789 +// -123.456 0 -123 +// -123.0000000 3 -123.000 +// -123.0000000 11 -123.0000000 +// -9999999999.9999999999 9 -10000000000.000000000 +// -9999999999.9999999999 10 -9999999999.9999999999 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Round/fs.fsproj b/snippets/fsharp/System/Decimal/Round/fs.fsproj new file mode 100644 index 00000000000..d4c1c8498c3 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Round/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Round/midpoint1.fs b/snippets/fsharp/System/Decimal/Round/midpoint1.fs new file mode 100644 index 00000000000..7c0237fe608 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Round/midpoint1.fs @@ -0,0 +1,28 @@ +module midpoint1 + +open System + +// +printfn $"""{"Value",-10} {"Default",-10} {"ToEven",-10} {"AwayFromZero",-15} {"ToZero",-15}""" +for value in 12m .. 0.1m .. 13m do + printfn "%-10O %-10O %-10O %-15O %-15O" + value + (Math.Round value) + (Math.Round(value, MidpointRounding.ToEven)) + (Math.Round(value, MidpointRounding.AwayFromZero)) + (Math.Round(value, MidpointRounding.ToZero)) + +// The example displays the following output: +// Value Default ToEven AwayFromZero ToZero +// 12.0 12 12 12 12 +// 12.1 12 12 12 12 +// 12.2 12 12 12 12 +// 12.3 12 12 12 12 +// 12.4 12 12 12 12 +// 12.5 12 12 13 12 +// 12.6 13 13 13 12 +// 12.7 13 13 13 12 +// 12.8 13 13 13 12 +// 12.9 13 13 13 12 +// 13.0 13 13 13 13 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/Round/mpr.fs b/snippets/fsharp/System/Decimal/Round/mpr.fs new file mode 100644 index 00000000000..8099e6ba8d1 --- /dev/null +++ b/snippets/fsharp/System/Decimal/Round/mpr.fs @@ -0,0 +1,78 @@ +module mpr + +// This example demonstrates the Math.Round() method in conjunction +// with the MidpointRounding enumeration and decimal places. +open System + +let decimalExample () = + // + // Round a positive value using different strategies. + // The precision of the result is 1 decimal place. + + let result = Math.Round(3.45m, 1, MidpointRounding.ToEven) + printfn $"{result} = Math.Round({3.45m}, 1, MidpointRounding.ToEven)" + let result = Math.Round(3.45m, 1, MidpointRounding.AwayFromZero) + printfn $"{result} = Math.Round({3.45m}, 1, MidpointRounding.AwayFromZero)" + let result = Math.Round(3.47m, 1, MidpointRounding.ToZero) + printfn $"{result} = Math.Round({3.47m}, 1, MidpointRounding.ToZero)\n" + + // Round a negative value using different strategies. + // The precision of the result is 1 decimal place. + + let result = Math.Round(-3.45m, 1, MidpointRounding.ToEven) + printfn $"{result} = Math.Round({-3.45m}, 1, MidpointRounding.ToEven)" + let result = Math.Round(-3.45m, 1, MidpointRounding.AwayFromZero) + printfn $"{result} = Math.Round({-3.45m}, 1, MidpointRounding.AwayFromZero)" + let result = Math.Round(-3.47m, 1, MidpointRounding.ToZero) + printfn $"{result} = Math.Round({-3.47m}, 1, MidpointRounding.ToZero)\n" + + // This code example produces the following results: + + // 3.4 = Math.Round(3.45, 1, MidpointRounding.ToEven) + // 3.5 = Math.Round(3.45, 1, MidpointRounding.AwayFromZero) + // 3.4 = Math.Round(3.47, 1, MidpointRounding.ToZero) + + // -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven) + // -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero) + // -3.4 = Math.Round(-3.47, 1, MidpointRounding.ToZero) + + // + +let doubleExample () = + // + // Round a positive and a negative value using the default. + let result = Math.Round(3.45, 1) + printfn $"{result,4} = Math.Round({3.45,5}, 1)" + let result = Math.Round(-3.45, 1) + printfn $"{result,4} = Math.Round({-3.45,5}, 1)\n" + + // Round a positive value using a MidpointRounding value. + let result = Math.Round(3.45, 1, MidpointRounding.ToEven) + printfn $"{result,4} = Math.Round({3.45,5}, 1, MidpointRounding.ToEven)" + let result = Math.Round(3.45, 1, MidpointRounding.AwayFromZero) + printfn $"{result,4} = Math.Round({3.45,5}, 1, MidpointRounding.AwayFromZero)" + let result = Math.Round(3.47, 1, MidpointRounding.ToZero) + printfn $"{result,4} = Math.Round({3.47,5}, 1, MidpointRounding.ToZero)\n" + + // Round a negative value using a MidpointRounding value. + let result = Math.Round(-3.45, 1, MidpointRounding.ToEven) + printfn $"{result,4} = Math.Round({-3.45,5}, 1, MidpointRounding.ToEven)" + let result = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero) + printfn $"{result,4} = Math.Round({-3.45,5}, 1, MidpointRounding.AwayFromZero)" + let result = Math.Round(-3.47, 1, MidpointRounding.ToZero) + printfn $"{result,4} = Math.Round({-3.47,5}, 1, MidpointRounding.ToZero)\n" + + // The example displays the following output: + + // 3.4 = Math.Round( 3.45, 1) + // -3.4 = Math.Round(-3.45, 1) + + // 3.4 = Math.Round(3.45, 1, MidpointRounding.ToEven) + // 3.5 = Math.Round(3.45, 1, MidpointRounding.AwayFromZero) + // 3.4 = Math.Round(3.47, 1, MidpointRounding.ToZero) + + // -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven) + // -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero) + // -3.4 = Math.Round(-3.47, 1, MidpointRounding.ToZero) + + // \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToByte/fs.fsproj b/snippets/fsharp/System/Decimal/ToByte/fs.fsproj new file mode 100644 index 00000000000..fda79617c38 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToByte/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToByte/tobyte_1.fs b/snippets/fsharp/System/Decimal/ToByte/tobyte_1.fs new file mode 100644 index 00000000000..ef30997c498 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToByte/tobyte_1.fs @@ -0,0 +1,29 @@ +// +open System + +let values = + [ 123m; Decimal(78000, 0, 0, false, 3uy) + 78.999m; 255.999m; 256m + 127.999m; 128m; -0.999m + -1m; -128.999m; -129m ] + +for value in values do + try + let number = Decimal.ToByte value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 78 --> 78 +// 78.000 --> 78 +// 78.999 --> 78 +// 255.999 --> 255 +// OverflowException: 256 +// 127.999 --> 127 +// 128 --> 128 +// -0.999 --> 0 +// OverflowException: -1 +// OverflowException: -128.999 +// OverflowException: -129 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToDouble/fs.fsproj b/snippets/fsharp/System/Decimal/ToDouble/fs.fsproj new file mode 100644 index 00000000000..6351d55369f --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToDouble/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToDouble/tosgl_dbl.fs b/snippets/fsharp/System/Decimal/ToDouble/tosgl_dbl.fs new file mode 100644 index 00000000000..1b3e705f09f --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToDouble/tosgl_dbl.fs @@ -0,0 +1,55 @@ +// +// Example of the Decimal.ToSingle and Decimal.ToDouble methods. +open System + +let formatter obj1 obj2 obj3 = printfn $"{obj1,30}{obj2,17}{obj3,23}" + +// Convert the decimal argument no exceptions are thrown. +let decimalToSgl_Dbl argument = + // Convert the argument to a float value. + let singleValue = Decimal.ToSingle argument + + // Convert the argument to a double value. + let doubleValue = Decimal.ToDouble argument + + formatter argument singleValue doubleValue + +printfn + """This example of the + Decimal.ToSingle( decimal ) and + Decimal.ToDouble( decimal ) +methods generates the following output. It +displays several converted decimal values. +""" + +formatter "decimal argument" "float" "double" +formatter "----------------" "-----" "------" + +// Convert decimal values and display the results. +decimalToSgl_Dbl 0.0000000000000000000000000001M +decimalToSgl_Dbl 0.0000000000123456789123456789M +decimalToSgl_Dbl 123M +decimalToSgl_Dbl (Decimal(123000000, 0, 0, false, 6uy)) +decimalToSgl_Dbl 123456789.123456789M +decimalToSgl_Dbl 123456789123456789123456789M +decimalToSgl_Dbl Decimal.MinValue +decimalToSgl_Dbl Decimal.MaxValue + + +// This example of the +// Decimal.ToSingle( decimal ) and +// Decimal.ToDouble( decimal ) +// methods generates the following output. It +// displays several converted decimal values. +// +// decimal argument float double +// ---------------- ----- ------ +// 0.0000000000000000000000000001 1E-28 1E-28 +// 0.0000000000123456789123456789 1.234568E-11 1.23456789123457E-11 +// 123 123 123 +// 123.000000 123 123 +// 123456789.123456789 1.234568E+08 123456789.123457 +// 123456789123456789123456789 1.234568E+26 1.23456789123457E+26 +// -79228162514264337593543950335 -7.922816E+28 -7.92281625142643E+28 +// 79228162514264337593543950335 7.922816E+28 7.92281625142643E+28 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt16/fs.fsproj b/snippets/fsharp/System/Decimal/ToInt16/fs.fsproj new file mode 100644 index 00000000000..afbd917e787 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt16/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt16/toint16_1.fs b/snippets/fsharp/System/Decimal/ToInt16/toint16_1.fs new file mode 100644 index 00000000000..d2bbdba00ea --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt16/toint16_1.fs @@ -0,0 +1,29 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 65535.999m; 65536m + 32767.999m; 32768m; -0.999m + -1m; -32768.999m; -32769m ] + +for value in values do + try + let number = Decimal.ToInt16 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// OverflowException: 65535.999 +// OverflowException: 65536 +// 32767.999 --> 32767 +// OverflowException: 32768 +// -0.999 --> 0 +// -1 --> -1 +// -32768.999 --> -32768 +// OverflowException: -32769 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt32/fs.fsproj b/snippets/fsharp/System/Decimal/ToInt32/fs.fsproj new file mode 100644 index 00000000000..78fc6ffa6b6 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt32/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt32/toint32_1.fs b/snippets/fsharp/System/Decimal/ToInt32/toint32_1.fs new file mode 100644 index 00000000000..ef1bc663b28 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt32/toint32_1.fs @@ -0,0 +1,30 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 4294967295.999m; 4294967296m + 4294967296m; 2147483647.999m; 2147483648m + -0.999m; -1m; -2147483648.999m; -2147483649m ] + +for value in values do + try + let number = Decimal.ToInt32 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// OverflowException: 4294967295.999 +// OverflowException: 4294967296 +// OverflowException: 4294967296 +// 2147483647.999 --> 2147483647 +// OverflowException: 2147483648 +// -0.999 --> 0 +// -1 --> -1 +// -2147483648.999 --> -2147483648 +// OverflowException: -2147483649 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt64/fs.fsproj b/snippets/fsharp/System/Decimal/ToInt64/fs.fsproj new file mode 100644 index 00000000000..90e94be3215 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt64/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToInt64/toint64_1.fs b/snippets/fsharp/System/Decimal/ToInt64/toint64_1.fs new file mode 100644 index 00000000000..c322a888514 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToInt64/toint64_1.fs @@ -0,0 +1,31 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 18446744073709551615.999m + 18446744073709551616m; 9223372036854775807.999m + 9223372036854775808m; -0.999m; -1m + -9223372036854775808.999m + -9223372036854775809m ] + +for value in values do + try + let number = Decimal.ToInt64 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// OverflowException: 18446744073709551615.999 +// OverflowException: 18446744073709551616 +// 9223372036854775807.999 --> 9223372036854775807 +// OverflowException: 9223372036854775808 +// -0.999 --> 0 +// -1 --> -1 +// -9223372036854775808.999 --> -9223372036854775808 +// OverflowException: -9223372036854775809 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToSByte/fs.fsproj b/snippets/fsharp/System/Decimal/ToSByte/fs.fsproj new file mode 100644 index 00000000000..88f316581c1 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToSByte/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToSByte/tosbyte1.fs b/snippets/fsharp/System/Decimal/ToSByte/tosbyte1.fs new file mode 100644 index 00000000000..ab1b07b10d5 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToSByte/tosbyte1.fs @@ -0,0 +1,29 @@ +// +open System + +let values = + [ 123m; Decimal(78000, 0, 0, false, 3uy) + 78.999m; 255.999m; 256m + 127.999m; 128m; -0.999m + -1m; -128.999m; -129m ] + +for value in values do + try + let number = Decimal.ToSByte value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 78 --> 78 +// 78.000 --> 78 +// 78.999 --> 78 +// OverflowException: 255.999 +// OverflowException: 256 +// 127.999 --> 127 +// OverflowException: 128 +// -0.999 --> 0 +// -1 --> -1 +// -128.999 --> -128 +// OverflowException: -129 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToString/ToString2.fs b/snippets/fsharp/System/Decimal/ToString/ToString2.fs new file mode 100644 index 00000000000..c3d7e841db1 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToString/ToString2.fs @@ -0,0 +1,122 @@ +open System +open System.Globalization + +let callDefaultToString () = + // + let value = -16325.62m + // Display value using default ToString method. + printfn $"{value.ToString()}" // Displays -16325.62 + // Display value using some standard format specifiers. + printfn $"""{value.ToString "G"}""" // Displays -16325.62 + printfn $"""{value.ToString "C"}""" // Displays ($16,325.62) + printfn $"""{value.ToString "F"}""" // Displays -16325.62 + // + +let callToStringWithSpecificCultures () = + // + let value = -16325.62m + // Display value using the invariant culture. + printfn $"{value.ToString CultureInfo.InvariantCulture}" + // Display value using the en-GB culture. + printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "en-GB")}""" + // Display value using the de-DE culture. + printfn $"""{value.ToString(CultureInfo.CreateSpecificCulture "de-DE")}""" + // This example displays the following output to the console: + // -16325.62 + // -16325.62 + // -16325,62 + // + +let callWithSpecificSpecifiers () = + // + let value = 16325.62m + + // Use standard numeric format specifiers. + let specifier = "G" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: G: 16325.62 + let specifier = "C" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: C: $16,325.62 + let specifier = "E04" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: E04: 1.6326E+004 + let specifier = "F" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: F: 16325.62 + let specifier = "N" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: N: 16,325.62 + let specifier = "P" + printfn $"{specifier}: {(value / 10000m).ToString specifier}" + // Displays: P: 163.26 % + + // Use custom numeric format specifiers. + let specifier = "0,0.000" + printfn $"{specifier}: {value.ToString specifier}" + // Displays: 0,0.000: 16,325.620 + let specifier = "#,#.00#(#,#.00#)" + printfn $"{specifier}: {(value * -1m).ToString specifier}" + // Displays: #,#.00#(#,#.00#): (16,325.62) + // + +let callWithSpecificSpecifiersAndCultures () = + // + let value = 16325.62m + + // Use standard numeric format specifiers. + let specifier = "G" + let culture = CultureInfo.CreateSpecificCulture "eu-ES" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 16325,62 + Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture)) + // Displays: 16325.62 + + let specifier = "C" + let culture = CultureInfo.CreateSpecificCulture "en-US" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: $16,325.62 + let culture = CultureInfo.CreateSpecificCulture "en-GB" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: £16,325.62 + + let specifier = "E04" + let culture = CultureInfo.CreateSpecificCulture "sv-SE" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 1,6326E+004 + let culture = CultureInfo.CreateSpecificCulture "en-NZ" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 1.6326E+004 + + let specifier = "F" + let culture = CultureInfo.CreateSpecificCulture "fr-FR" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 16325,62 + let culture = CultureInfo.CreateSpecificCulture "en-CA" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 16325.62 + + let specifier = "N" + let culture = CultureInfo.CreateSpecificCulture "es-ES" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 16.325,62 + let culture = CultureInfo.CreateSpecificCulture "fr-CA" + Console.WriteLine(value.ToString(specifier, culture)) + // Displays: 16 325,62 + + let specifier = "P" + let culture = CultureInfo.InvariantCulture + printfn $"{(value / 10000m).ToString(specifier, culture)}" + // Displays: 163.26 % + let culture = CultureInfo.CreateSpecificCulture "ar-EG" + printfn $"{(value / 10000m).ToString(specifier, culture)}" + // Displays: 163.256 % + // + +callDefaultToString() +printfn "-----" +callToStringWithSpecificCultures() +printfn "-----" +callWithSpecificSpecifiers() +printfn "-----" +callWithSpecificSpecifiersAndCultures() \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToString/fs.fsproj b/snippets/fsharp/System/Decimal/ToString/fs.fsproj new file mode 100644 index 00000000000..bd48594efd1 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToString/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt16/fs.fsproj b/snippets/fsharp/System/Decimal/ToUInt16/fs.fsproj new file mode 100644 index 00000000000..a321ec32264 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt16/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt16/touint16_1.fs b/snippets/fsharp/System/Decimal/ToUInt16/touint16_1.fs new file mode 100644 index 00000000000..a1bfc24eaad --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt16/touint16_1.fs @@ -0,0 +1,29 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 65535.999m; 65536m; + 32767.999m; 32768m; -0.999m; + -1m; -32768.999m; -32769m ] + +for value in values do + try + let number = Decimal.ToUInt16 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// 65535.999 --> 65535 +// OverflowException: 65536 +// 32767.999 --> 32767 +// 32768 --> 32768 +// -0.999 --> 0 +// OverflowException: -1 +// OverflowException: -32768.999 +// OverflowException: -32769 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt32/fs.fsproj b/snippets/fsharp/System/Decimal/ToUInt32/fs.fsproj new file mode 100644 index 00000000000..f2f6b1dc748 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt32/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt32/touint32_1.fs b/snippets/fsharp/System/Decimal/ToUInt32/touint32_1.fs new file mode 100644 index 00000000000..1e09f2b4cff --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt32/touint32_1.fs @@ -0,0 +1,30 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 4294967295.999m; 4294967296m + 4294967296m; 2147483647.999m; 2147483648m + -0.999m; -1m; -2147483648.999m; -2147483649m ] + +for value in values do + try + let number = Decimal.ToUInt32 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// 4294967295.999 --> 4294967295 +// OverflowException: 4294967296 +// OverflowException: 4294967296 +// 2147483647.999 --> 2147483647 +// 2147483648 --> 2147483648 +// -0.999 --> 0 +// OverflowException: -1 +// OverflowException: -2147483648.999 +// OverflowException: -2147483649 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt64/fs.fsproj b/snippets/fsharp/System/Decimal/ToUInt64/fs.fsproj new file mode 100644 index 00000000000..bca93484410 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt64/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/ToUInt64/touint64_1.fs b/snippets/fsharp/System/Decimal/ToUInt64/touint64_1.fs new file mode 100644 index 00000000000..d8ffce3f943 --- /dev/null +++ b/snippets/fsharp/System/Decimal/ToUInt64/touint64_1.fs @@ -0,0 +1,31 @@ +// +open System + +let values = + [ 123m; Decimal(123000, 0, 0, false, 3uy) + 123.999m; 18446744073709551615.999m + 18446744073709551616m; 9223372036854775807.999m + 9223372036854775808m; -0.999m; -1m + -9223372036854775808.999m + -9223372036854775809m ] + +for value in values do + try + let number = Decimal.ToUInt64 value + printfn $"{value} --> {number}" + with :? OverflowException as e -> + printfn $"{e.GetType().Name}: {value}" + +// The example displays the following output: +// 123 --> 123 +// 123.000 --> 123 +// 123.999 --> 123 +// 18446744073709551615.999 --> 18446744073709551615 +// OverflowException: 18446744073709551616 +// 9223372036854775807.999 --> 9223372036854775807 +// 9223372036854775808 --> 9223372036854775808 +// -0.999 --> 0 +// OverflowException: -1 +// OverflowException: -9223372036854775808.999 +// OverflowException: -9223372036854775809 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/TryParse/TryParse.fs b/snippets/fsharp/System/Decimal/TryParse/TryParse.fs new file mode 100644 index 00000000000..889150db44d --- /dev/null +++ b/snippets/fsharp/System/Decimal/TryParse/TryParse.fs @@ -0,0 +1,93 @@ +open System +open System.Globalization + +let callTryParse1 () = + // + // Parse a floating-point value with a thousands separator. + let value = "1,643.57" + match Decimal.TryParse value with + | true, number -> + printfn $"{number}" + | _ -> + printfn $"Unable to parse '{value}'." + + // Parse a floating-point value with a currency symbol and a + // thousands separator. + let value = "$1,643.57" + match Decimal.TryParse value with + | true, number -> + printfn $"{number}" + | _ -> + printfn $"Unable to parse '{value}'." + + // Parse value in exponential notation. + let value = "-1.643e6" + match Decimal.TryParse value with + | true, number -> + printfn $"{number}" + | _ -> + printfn $"Unable to parse '{value}'." + + // Parse a negative integer value. + let value = "-1689346178821" + match Decimal.TryParse value with + | true, number -> + printfn $"{number}" + | _ -> + printfn $"Unable to parse '{value}'." + // The example displays the following output to the console: + // 1643.57 + // Unable to parse '$1,643.57'. + // Unable to parse '-1.643e6'. + // -1689346178821 + // + +let callTryParse2 () = + // + // Parse currency value using en-GB culture. + let value = "£1,097.63" + let style = NumberStyles.Number ||| NumberStyles.AllowCurrencySymbol + let culture = CultureInfo.CreateSpecificCulture "en-GB" + match Decimal.TryParse(value, style, culture) with + | true, number -> + printfn $"Converted '{value}' to {number}." + | _ -> + printfn $"Unable to convert '{value}'." + // Displays: + // Converted '£1,097.63' to 1097.63. + + let value = "1345,978" + let style = NumberStyles.AllowDecimalPoint + let culture = CultureInfo.CreateSpecificCulture "fr-FR" + match Decimal.TryParse(value, style, culture) with + | true, number -> + printfn $"Converted '{value}' to {number}." + | _ -> + printfn $"Unable to convert '{value}'." + // Displays: + // Converted '1345,978' to 1345.978. + + let value = "1.345,978" + let style = NumberStyles.AllowDecimalPoint ||| NumberStyles.AllowThousands + let culture = CultureInfo.CreateSpecificCulture "es-ES" + match Decimal.TryParse(value, style, culture) with + | true, number -> + printfn $"Converted '{value}' to {number}." + | _ -> + printfn $"Unable to convert '{value}'." + // Displays: + // Converted '1.345,978' to 1345.978. + + let value = "1 345,978" + match Decimal.TryParse(value, style, culture) with + | true, number -> + printfn $"Converted '{value}' to {number}." + | _ -> + printfn $"Unable to convert '{value}'." + // Displays: + // Unable to convert '1 345,978'. + // + +callTryParse1 () +printfn "----------" +callTryParse2 () \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/TryParse/fs.fsproj b/snippets/fsharp/System/Decimal/TryParse/fs.fsproj new file mode 100644 index 00000000000..f280b3ec57e --- /dev/null +++ b/snippets/fsharp/System/Decimal/TryParse/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/addition1.fs b/snippets/fsharp/System/Decimal/op_Addition/addition1.fs new file mode 100644 index 00000000000..531c3a1080b --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/addition1.fs @@ -0,0 +1,11 @@ +module addition1 + +// +let number1 = 120.07m +let number2 = 163.19m +let number3 = number1 + number2 +printfn $"{number1} + {number2} = {number3}" + +// The example displays the following output: +// 120.07 + 163.19 = 283.26 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/decrement1.fs b/snippets/fsharp/System/Decimal/op_Addition/decrement1.fs new file mode 100644 index 00000000000..d65c459a257 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/decrement1.fs @@ -0,0 +1,11 @@ +module decrement1 + +// +let number = 1079.8m +printfn $"Original value: {number:N}" +printfn $"Decremented value: {- -number:N}" + +// The example displays the following output: +// Original value: 1,079.80 +// Decremented value: 1,078.80 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/decrement2.fs b/snippets/fsharp/System/Decimal/op_Addition/decrement2.fs new file mode 100644 index 00000000000..413de2c7bf9 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/decrement2.fs @@ -0,0 +1,13 @@ +module decrement2 + +// +open System + +let number = 1079.8m +printfn $"Original value: {number:N}" +printfn $"Decremented value: {Decimal.Subtract(number, 1):N}" + +// The example displays the following output: +// Original value: 1,079.80 +// Decremented value: 1,078.80 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/division1.fs b/snippets/fsharp/System/Decimal/op_Addition/division1.fs new file mode 100644 index 00000000000..aa0cbde8cec --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/division1.fs @@ -0,0 +1,11 @@ +module division1 + +// +let number1 = 16.8m +let number2 = 4.1m +let number3 = number1 / number2 +printfn $"{number1:N2} / {number2:N2} = {number3:N2}" + +// The example displays the following output: +// 16.80 / 4.10 = 4.10 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/equality1.fs b/snippets/fsharp/System/Decimal/op_Addition/equality1.fs new file mode 100644 index 00000000000..fda6e9c379e --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/equality1.fs @@ -0,0 +1,17 @@ +module equality1 + +// +open System + +let number1 = 16354.0695m +let number2 = 16354.0699m +printfn $"{number1} = {number2}: {number1 = number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{rounded1} = {rounded2}: {rounded1 = rounded2}" + +// The example displays the following output: +// 16354.0695 = 16354.0699: False +// 16354.07 = 16354.07: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/fs.fsproj b/snippets/fsharp/System/Decimal/op_Addition/fs.fsproj new file mode 100644 index 00000000000..042ad949745 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/fs.fsproj @@ -0,0 +1,23 @@ + + + Exe + net6.0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/greaterthan1.fs b/snippets/fsharp/System/Decimal/op_Addition/greaterthan1.fs new file mode 100644 index 00000000000..1fa46905051 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/greaterthan1.fs @@ -0,0 +1,17 @@ +module greaterthan1 + +// +open System + +let number1 = 16354.0699m +let number2 = 16354.0695m +printfn $"{number1} > {number2}: {number1 > number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{number1} > {number2}: {number1 > number2}" + +// The example displays the following output: +// 16354.0699 > 16354.0695: True +// 16354.07 > 16354.07: False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/greaterthanorequal1.fs b/snippets/fsharp/System/Decimal/op_Addition/greaterthanorequal1.fs new file mode 100644 index 00000000000..8105cf2bf4d --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/greaterthanorequal1.fs @@ -0,0 +1,17 @@ +module greaterthanorequal1 + +// +open System + +let number1 = 16354.0699m +let number2 = 16354.0695m +printfn $"{number1} >= {number2}: {number1 >= number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{number1} >= {number2}: {number1 >= number2}" + +// The example displays the following output: +// 16354.0699 >= 16354.0695: True +// 16354.07 >= 16354.07: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/increment1.fs b/snippets/fsharp/System/Decimal/op_Addition/increment1.fs new file mode 100644 index 00000000000..9ee3d80d7cd --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/increment1.fs @@ -0,0 +1,13 @@ +module increment1 + +// +open System + +let number = 1079.8m +printfn $"Original value: {number:N}" +printfn $"Incremented value: {Decimal.op_Increment number:N}" + +// The example displays the following output: +// Original value: 1,079.80 +// Incremented value: 1,080.80 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/increment2.fs b/snippets/fsharp/System/Decimal/op_Addition/increment2.fs new file mode 100644 index 00000000000..8d9b5510123 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/increment2.fs @@ -0,0 +1,13 @@ +module increment2 + +// +open System + +let number = 1079.8m +printfn $"Original value: {number:N}" +printfn $"Incremented value: {Decimal.Add(number, 1):N}" + +// The example displays the following output: +// Original value: 1,079.80 +// Incremented value: 1,080.80 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/inequality1.fs b/snippets/fsharp/System/Decimal/op_Addition/inequality1.fs new file mode 100644 index 00000000000..f3b2b556655 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/inequality1.fs @@ -0,0 +1,17 @@ +module inequality1 + +// +open System + +let number1 = 16354.0695m +let number2 = 16354.0699m +printfn $"{number1} <> {number2}: {number1 <> number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{rounded1} <> {rounded2}: {rounded1 <> rounded2}" + +// The example displays the following output: +// 16354.0695 <> 16354.0699: True +// 16354.07 <> 16354.07: False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/lessthan1.fs b/snippets/fsharp/System/Decimal/op_Addition/lessthan1.fs new file mode 100644 index 00000000000..a52f06e3022 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/lessthan1.fs @@ -0,0 +1,17 @@ +module lessthan1 + +// +open System + +let number1 = 16354.0699m +let number2 = 16354.0695m +printfn $"{number1} < {number2}: {number1 < number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{rounded1} < {rounded2}: {rounded1 < rounded2}" + +// The example displays the following output: +// 16354.0699 < 16354.0695: False +// 16354.07 < 16354.07: False +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/lessthanorequal1.fs b/snippets/fsharp/System/Decimal/op_Addition/lessthanorequal1.fs new file mode 100644 index 00000000000..9f11558cf4b --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/lessthanorequal1.fs @@ -0,0 +1,17 @@ +module lessthanorequal1 + +// +open System + +let number1 = 16354.0699m +let number2 = 16354.0695m +printfn $"{number1} <= {number2}: {number1 <= number2}" + +let rounded1 = Decimal.Round(number1, 2) +let rounded2 = Decimal.Round(number2, 2) +printfn $"{rounded1} <= {rounded2}: {rounded1 <= rounded2}" + +// The example displays the following output: +// 16354.0699 <= 16354.0695: False +// 16354.07 <= 16354.07: True +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/modulus1.fs b/snippets/fsharp/System/Decimal/op_Addition/modulus1.fs new file mode 100644 index 00000000000..b10c10383da --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/modulus1.fs @@ -0,0 +1,11 @@ +module modulus + +// +let number1 = 16.8m +let number2 = 4.1m +let number3 = number1 % number2 +printfn $"{number1:N2} %% {number2:N2} = {number3:N2}" + +// The example displays the following output: +// 16.80 % 4.10 = 0.40 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/multiply1.fs b/snippets/fsharp/System/Decimal/op_Addition/multiply1.fs new file mode 100644 index 00000000000..962db556f06 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/multiply1.fs @@ -0,0 +1,11 @@ +module multiply1 + +// +let number1 = 16.8m +let number2 = 4.1m +let number3 = number1 * number2 +printfn $"{number1:N2} x {number2:N2} = {number3:N2}" + +// The example displays the following output: +// 16.80 x 4.10 = 68.88 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Addition/subtraction1.fs b/snippets/fsharp/System/Decimal/op_Addition/subtraction1.fs new file mode 100644 index 00000000000..67cdbcfdab4 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Addition/subtraction1.fs @@ -0,0 +1,11 @@ +module subtraction1 + +// +let number1 = 120.07m +let number2 = 163.19m +let number3 = number1 - number2 +printfn $"{number1} - {number2} = {number3}" + +// The example displays the following output: +// 120.07 - 163.19 = -43.12 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/cfromchar.fs b/snippets/fsharp/System/Decimal/op_Explicit/cfromchar.fs new file mode 100644 index 00000000000..9da73909e35 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/cfromchar.fs @@ -0,0 +1,20 @@ +module cfromchar + +// +// Define a list of Char values. +let values = [ '\000'; ' '; '*'; 'A'; 'a'; '{'; 'Æ' ] + +// Convert each Char value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"'{value}' ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// ' ' (Char) --> 0 (Decimal) +// ' ' (Char) --> 32 (Decimal) +// '*' (Char) --> 42 (Decimal) +// 'A' (Char) --> 65 (Decimal) +// 'a' (Char) --> 97 (Decimal) +// '{' (Char) --> 123 (Decimal) +// 'Æ' (Char) --> 198 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/cfromdouble.fs b/snippets/fsharp/System/Decimal/op_Explicit/cfromdouble.fs new file mode 100644 index 00000000000..b0c58f2b8e8 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/cfromdouble.fs @@ -0,0 +1,51 @@ +module cfromdouble + +// +// Example of the explicit conversion from double to decimal. +let print obj1 obj2 = printfn $"{obj1,25:E16}{obj2,33}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Convert the double argument; catch exceptions that are thrown. +let decimalFromDouble (argument: double) = + // Convert the double argument to a decimal value. + try + decimal argument + |> print argument + with ex -> + getExceptionType ex + |> print argument + + +printfn "This example of the explicit conversion from double to decimal \ngenerates the following output.\n" +print "double argument" "decimal value" +print "---------------" "-------------" + +// Convert double values and display the results. +decimalFromDouble 1.234567890123E-30 +decimalFromDouble 1.2345678901234E-25 +decimalFromDouble 1.23456789012345E-20 +decimalFromDouble 1.234567890123456E-10 +decimalFromDouble 1.2345678901234567 +decimalFromDouble 1.23456789012345678E+12 +decimalFromDouble 1.234567890123456789E+28 +decimalFromDouble 1.234567890123456789E+30 + + +// This example of the explicit conversion from double to decimal +// generates the following output. + +// double argument decimal value +// --------------- ------------- +// 1.2345678901230000E-030 0 +// 1.2345678901233999E-025 0.0000000000000000000000001235 +// 1.2345678901234499E-020 0.0000000000000000000123456789 +// 1.2345678901234560E-010 0.000000000123456789012346 +// 1.2345678901234567E+000 1.23456789012346 +// 1.2345678901234568E+012 1234567890123.46 +// 1.2345678901234568E+028 12345678901234600000000000000 +// 1.2345678901234569E+030 OverflowException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/cfromsingle.fs b/snippets/fsharp/System/Decimal/op_Explicit/cfromsingle.fs new file mode 100644 index 00000000000..abda8208835 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/cfromsingle.fs @@ -0,0 +1,50 @@ +module cfromsingle + +// +// Example of the explicit conversion from float to decimal. +let print obj1 obj2 = printfn $"{obj1,16:E7}{obj2,33}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Convert the float argument; catch exceptions that are thrown. +let decimalFromSingle (argument: float32) = + // Convert the float argument to a decimal value. + try + decimal argument + |> print argument + with ex -> + getExceptionType ex + |> print argument + +printfn "This example of the explicit conversion from float to decimal \ngenerates the following output.\n" +print "float argument" "decimal value" +print "--------------" "-------------" + +// Convert float values and display the results. +decimalFromSingle 1.2345E-30f +decimalFromSingle 1.2345E-26f +decimalFromSingle 1.23456E-22f +decimalFromSingle 1.23456E-12f +decimalFromSingle 1.234567f +decimalFromSingle 1.234567E+12f +decimalFromSingle 1.2345678E+28f +decimalFromSingle 1.2345678E+30f + + +// This example of the explicit conversion from float to decimal +// generates the following output. +// +// float argument decimal value +// -------------- ------------- +// 1.2345000E-030 0 +// 1.2345000E-026 0.0000000000000000000000000123 +// 1.2345600E-022 0.000000000000000000000123456 +// 1.2345600E-012 0.00000000000123456 +// 1.2345671E+000 1.234567 +// 1.2345670E+012 1234567000000 +// 1.2345678E+028 12345680000000000000000000000 +// 1.2345678E+030 OverflowException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctochar.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctochar.fs new file mode 100644 index 00000000000..5c9459e99f7 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctochar.fs @@ -0,0 +1,33 @@ +module ctochar + +// +open System + +// Define a list of decimal values. +let values = + [ 3.33m; 55.5m; 77.7m; 123m; 123.999m; 170m; 188.88m; 222m; 244m; 8217m; 8250m; 65536m; -1m ] + +// Convert each value to a Char. +for value in values do + try + let charValue = char value + printfn $"{value} --> {charValue} ({uint16 charValue:X4})" + + with :? OverflowException -> + printfn $"OverflowException: Cannot convert {value}" + +// The example displays the following output: +// 3.33 --> ? (0003) +// 55.5 --> 7 (0037) +// 77.7 --> M (004D) +// 123 --> { (007B) +// 123.999 --> { (007B) +// 170 --> ª (00AA) +// 188.88 --> ¼ (00BC) +// 222 --> _ (00DE) +// 244 --> ô (00F4) +// 8217 --> ' (2019) +// 8250 --> > (203A) +// OverflowException: Cannot convert 65536 +// OverflowException: Cannot convert -1 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctos_byte.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctos_byte.fs new file mode 100644 index 00000000000..a0a6122ba6e --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctos_byte.fs @@ -0,0 +1,32 @@ +module ctos_byte + +// +open System + +// Define a list of decimal values. +let values = + [ 78m; Decimal(78000, 0, 0, false, 3uy) + 78.999m; 255.999m; 256m; 127.999m + 128m; -0.999m; -1m; -128.999m; -129m ] + +for value in values do + try + let byteValue = byte value + printfn $"{value} ({value.GetType().Name}) --> {byteValue} ({byteValue.GetType().Name})" + + with :? OverflowException -> + printfn $"OverflowException: Cannot convert {value}" + +// The example displays the following output: +// 78 (Decimal) --> 78 (Byte) +// 78.000 (Decimal) --> 78 (Byte) +// 78.999 (Decimal) --> 78 (Byte) +// 255.999 (Decimal) --> 255 (Byte) +// OverflowException: Cannot convert 256 +// 127.999 (Decimal) --> 127 (Byte) +// 128 (Decimal) --> 128 (Byte) +// -0.999 (Decimal) --> 0 (Byte) +// OverflowException: Cannot convert -1 +// OverflowException: Cannot convert -128.999 +// OverflowException: Cannot convert -129 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctosgl_dbl.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctosgl_dbl.fs new file mode 100644 index 00000000000..22e662d543f --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctosgl_dbl.fs @@ -0,0 +1,29 @@ +module ctosgl_dbl + +// +open System + +// Define a list of decimal values. +let values = + [ 0.0000000000000000000000000001M + 0.0000000000123456789123456789M + 123M; Decimal(123000000, 0, 0, false, 6uy) + 123456789.123456789M + 123456789123456789123456789M + Decimal.MinValue; Decimal.MaxValue ] + +// Convert each value to a double. +for value in values do + let dblValue = double value + printfn $"{value} ({value.GetType().Name}) --> {dblValue} ({dblValue.GetType().Name})" + +// The example displays the following output: +// 0.0000000000000000000000000001 (Decimal) --> 1E-28 (Double) +// 0.0000000000123456789123456789 (Decimal) --> 1.23456789123457E-11 (Double) +// 123 (Decimal) --> 123 (Double) +// 123.000000 (Decimal) --> 123 (Double) +// 123456789.123456789 (Decimal) --> 123456789.123457 (Double) +// 123456789123456789123456789 (Decimal) --> 1.23456789123457E+26 (Double) +// -79228162514264337593543950335 (Decimal) --> -7.92281625142643E+28 (Double) +// 79228162514264337593543950335 (Decimal) --> 7.92281625142643E+28 (Double) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctou_int16.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int16.fs new file mode 100644 index 00000000000..cf9383be502 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int16.fs @@ -0,0 +1,65 @@ +module ctou_int16 + +// +// Example of the explicit conversions from decimal to short and +// decimal to ushort. +let print obj1 obj2 obj3 = + printfn $"{obj1, 16}{obj2, 19}{obj3, 19}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Convert the decimal argument; catch exceptions that are thrown. +let decimalToU_Int16 (argument: decimal) = + let int16Value: obj = + // Convert the argument to a int16 value. + try + int16 argument + with ex -> getExceptionType ex + + let uint16Value: obj = + // Convert the argument to a uint16 value. + try + uint16 argument + with ex -> getExceptionType ex + + print argument int16Value uint16Value + +printfn "This example of the explicit conversions from decimal to short\nand decimal to ushort generates the following output. It displays \nseveral converted decimal values.\n" +print "decimal argument" "short/exception" "ushort/exception" +print "----------------" "---------------" "----------------" + +// Convert decimal values and display the results. +decimalToU_Int16 123M +decimalToU_Int16 (new decimal (123000, 0, 0, false, 3uy)) +decimalToU_Int16 123.999M +decimalToU_Int16 65535.999M +decimalToU_Int16 65536M +decimalToU_Int16 32767.999M +decimalToU_Int16 32768M +decimalToU_Int16 -0.999M +decimalToU_Int16 -1M +decimalToU_Int16 -32768.999M +decimalToU_Int16 -32769M + + +// This example of the explicit conversions from decimal to short +// and decimal to ushort generates the following output. It displays +// several converted decimal values. +// +// decimal argument short/exception ushort/exception +// ---------------- --------------- ---------------- +// 123 123 123 +// 123.000 123 123 +// 123.999 123 123 +// 65535.999 OverflowException 65535 +// 65536 OverflowException OverflowException +// 32767.999 32767 32767 +// 32768 OverflowException 32768 +// -0.999 0 0 +// -1 -1 OverflowException +// -32768.999 -32768 OverflowException +// -32769 OverflowException OverflowException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctou_int32.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int32.fs new file mode 100644 index 00000000000..509db144449 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int32.fs @@ -0,0 +1,65 @@ +module ctou_int32 + +// +// Example of the explicit conversions from decimal to int and +// decimal to uint. +let print obj1 obj2 obj3 = printfn $"{obj1,17}{obj2,19}{obj3,19}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Convert the decimal argument; catch exceptions that are thrown. +let decimalToU_Int32 (argument: decimal) = + let int32Value: obj = + // Convert the argument to a int32 value. + try + int32 argument + with ex -> getExceptionType ex + + let uint32Value: obj = + // Convert the argument to a uint32 value. + try + uint32 argument + with ex -> getExceptionType ex + + print argument int32Value uint32Value + +printfn "This example of the explicit conversions from decimal to int\nand decimal to uint generates the following output. It displays\nseveral converted decimal values.\n" + +print "decimal argument" "int/exception" "uint/exception" +print "----------------" "-------------" "--------------" + +// Convert decimal values and display the results. +decimalToU_Int32 123M +decimalToU_Int32 (new decimal(123000, 0, 0, false, 3uy)) +decimalToU_Int32 123.999M +decimalToU_Int32 4294967295.999M +decimalToU_Int32 4294967296M +decimalToU_Int32 2147483647.999M +decimalToU_Int32 2147483648M +decimalToU_Int32 -0.999M +decimalToU_Int32 -1M +decimalToU_Int32 -2147483648.999M +decimalToU_Int32 -2147483649M + + +// This example of the explicit conversions from decimal to int +// and decimal to uint generates the following output. It displays +// several converted decimal values. +// +// decimal argument int/exception uint/exception +// ---------------- ------------- -------------- +// 123 123 123 +// 123.000 123 123 +// 123.999 123 123 +// 4294967295.999 OverflowException 4294967295 +// 4294967296 OverflowException OverflowException +// 2147483647.999 2147483647 2147483647 +// 2147483648 OverflowException 2147483648 +// -0.999 0 0 +// -1 -1 OverflowException +// -2147483648.999 -2147483648 OverflowException +// -2147483649 OverflowException OverflowException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/ctou_int64.fs b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int64.fs new file mode 100644 index 00000000000..f8f5c121e93 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/ctou_int64.fs @@ -0,0 +1,65 @@ +module ctou_int64 + +// +// Example of the explicit conversions from decimal to long and +// decimal to ulong. +let print obj1 obj2 obj3 = printfn $"{obj1,25}{obj2,22}{obj3,22}" + +// Get the exception type name; remove the namespace prefix. +let getExceptionType (ex: exn) = + let exceptionType = ex.GetType() |> string + exceptionType.Substring(exceptionType.LastIndexOf '.' + 1) + +// Convert the decimal argument; catch exceptions that are thrown. +let decimalToU_Int64 (argument: decimal) = + let int32Value: obj = + // Convert the argument to a int64 value. + try + int32 argument + with ex -> getExceptionType ex + + let uint32Value: obj = + // Convert the argument to a uint64 value. + try + uint32 argument + with ex -> getExceptionType ex + + print argument int32Value uint32Value + +printfn "This example of the explicit conversions from decimal to long\nand decimal to ulong generates the following output. It displays\nseveral converted decimal values.\n" + +print "decimal argument" "long/exception" "ulong/exception" +print "----------------" "--------------" "---------------" + +// Convert decimal values and display the results. +decimalToU_Int64 123M +decimalToU_Int64 (new decimal(123000, 0, 0, false, 3uy)) +decimalToU_Int64 123.999M +decimalToU_Int64 18446744073709551615.999M +decimalToU_Int64 18446744073709551616M +decimalToU_Int64 9223372036854775807.999M +decimalToU_Int64 9223372036854775808M +decimalToU_Int64 -0.999M +decimalToU_Int64 -1M +decimalToU_Int64 -9223372036854775808.999M +decimalToU_Int64 -9223372036854775809M + + +// This example of the explicit conversions from decimal to long +// and decimal to ulong generates the following output. It displays +// several converted decimal values. +// +// decimal argument long/exception ulong/exception +// ---------------- -------------- --------------- +// 123 123 123 +// 123.000 123 123 +// 123.999 123 123 +// 18446744073709551615.999 OverflowException 18446744073709551615 +// 18446744073709551616 OverflowException OverflowException +// 9223372036854775807.999 9223372036854775807 9223372036854775807 +// 9223372036854775808 OverflowException 9223372036854775808 +// -0.999 0 0 +// -1 -1 OverflowException +// -9223372036854775808.999 -9223372036854775808 OverflowException +// -9223372036854775809 OverflowException OverflowException +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/fs.fsproj b/snippets/fsharp/System/Decimal/op_Explicit/fs.fsproj new file mode 100644 index 00000000000..a0a20eb52e0 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/fs.fsproj @@ -0,0 +1,19 @@ + + + Exe + net6.0 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/tosbyte.fs b/snippets/fsharp/System/Decimal/op_Explicit/tosbyte.fs new file mode 100644 index 00000000000..591a4a3c37d --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/tosbyte.fs @@ -0,0 +1,30 @@ +module tosbyte + +// +open System + +// Define a list of decimal values. +let values = + [ 78m; Decimal(78000, 0, 0, false, 3uy) + 78.999m; 255.999m; 256m; 127.999m + 128m; -0.999m; -1m; -128.999m; -129m ] +for value in values do + try + let byteValue = int8 value + printfn $"{value} ({value.GetType().Name}) --> {byteValue} ({byteValue.GetType().Name})" + with :? OverflowException -> + printfn $"OverflowException: Cannot convert {value}" + +// The example displays the following output: +// 78 (Decimal) --> 78 (SByte) +// 78.000 (Decimal) --> 78 (SByte) +// 78.999 (Decimal) --> 78 (SByte) +// OverflowException: Cannot convert 255.999 +// OverflowException: Cannot convert 256 +// 127.999 (Decimal) --> 127 (SByte) +// OverflowException: Cannot convert 128 +// -0.999 (Decimal) --> 0 (SByte) +// -1 (Decimal) --> -1 (SByte) +// -128.999 (Decimal) --> -128 (SByte) +// OverflowException: Cannot convert -129 +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Explicit/tosingle1.fs b/snippets/fsharp/System/Decimal/op_Explicit/tosingle1.fs new file mode 100644 index 00000000000..347011a1552 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Explicit/tosingle1.fs @@ -0,0 +1,29 @@ +module tosingle1 + +// +open System + +// Define a list of decimal values. +let values = + [ 0.0000000000000000000000000001M + 0.0000000000123456789123456789M + 123M; Decimal(123000000, 0, 0, false, 6uy) + 123456789.123456789M + 123456789123456789123456789M + Decimal.MinValue; Decimal.MaxValue ] + +// Convert each value to a double. +for value in values do + let dblValue = float32 value + printfn $"{value} ({value.GetType().Name}) --> {dblValue} ({dblValue.GetType().Name})" + +// The example displays the following output: +// 0.0000000000000000000000000001 (Decimal) --> 1E-28 (Single) +// 0.0000000000123456789123456789 (Decimal) --> 1.234568E-11 (Single) +// 123 (Decimal) --> 123 (Single) +// 123.000000 (Decimal) --> 123 (Single) +// 123456789.123456789 (Decimal) --> 1.234568E+08 (Single) +// 123456789123456789123456789 (Decimal) --> 1.234568E+26 (Single) +// -79228162514264337593543950335 (Decimal) --> -7.922816E+28 (Single) +// 79228162514264337593543950335 (Decimal) --> 7.922816E+28 (Single) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfrombyte.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfrombyte.fs new file mode 100644 index 00000000000..8e9f16661d6 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfrombyte.fs @@ -0,0 +1,21 @@ +module cfrombyte + +// +open System + +// Define a list of byte values. +let values = + [ Byte.MinValue; Byte.MaxValue; 0x3Fuy; 123uy; 200uy ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// 0 (Byte) --> 0 (Decimal) +// 255 (Byte) --> 255 (Decimal) +// 63 (Byte) --> 63 (Decimal) +// 123 (Byte) --> 123 (Decimal) +// 200 (Byte) --> 200 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromint16.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromint16.fs new file mode 100644 index 00000000000..8e9d5bee0be --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromint16.fs @@ -0,0 +1,21 @@ +module cfromint16 + +// +open System + +// Define a list of 16-bit integer values. +let values = + [ Int16.MinValue; Int16.MaxValue; 0xFFFs; 12345s; -10000s ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// -32768 (Int16) --> -32768 (Decimal) +// 32767 (Int16) --> 32767 (Decimal) +// 4095 (Int16) --> 4095 (Decimal) +// 12345 (Int16) --> 12345 (Decimal) +// -10000 (Int16) --> -10000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromint32.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromint32.fs new file mode 100644 index 00000000000..ac011bca79d --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromint32.fs @@ -0,0 +1,21 @@ +module cfromint32 + +// +open System + +// Define a list of 32-bit integer values. +let values = + [ Int32.MinValue; Int32.MaxValue; 0xFFFFFF; 123456789; -1000000000 ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// -2147483648 (Int32) --> -2147483648 (Decimal) +// 2147483647 (Int32) --> 2147483647 (Decimal) +// 16777215 (Int32) --> 16777215 (Decimal) +// 123456789 (Int32) --> 123456789 (Decimal) +// -1000000000 (Int32) --> -1000000000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromint64.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromint64.fs new file mode 100644 index 00000000000..db4a3056c7e --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromint64.fs @@ -0,0 +1,21 @@ +module cfromint64 + +// +open System + +// Define a list of 64-bit integer values. +let values = + [ Int64.MinValue; Int64.MaxValue; 0xFFFFFFFFFFFFL; 123456789123456789L; -1000000000000000L ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// -9223372036854775808 (Int64) --> -9223372036854775808 (Decimal) +// 9223372036854775807 (Int64) --> 9223372036854775807 (Decimal) +// 281474976710655 (Int64) --> 281474976710655 (Decimal) +// 123456789123456789 (Int64) --> 123456789123456789 (Decimal) +// -1000000000000000 (Int64) --> -1000000000000000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromsbyte.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromsbyte.fs new file mode 100644 index 00000000000..12ccadb2fe4 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromsbyte.fs @@ -0,0 +1,21 @@ +module cfromsbyte + +// +open System + +// Define a list of 8-bit signed integer values. +let values = + [ SByte.MinValue; SByte.MaxValue; 0x3Fy; 123y; -100y ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// -128 (SByte) --> -128 (Decimal) +// 127 (SByte) --> 127 (Decimal) +// 63 (SByte) --> 63 (Decimal) +// 123 (SByte) --> 123 (Decimal) +// -100 (SByte) --> -100 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromuint16.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint16.fs new file mode 100644 index 00000000000..0f4bd619245 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint16.fs @@ -0,0 +1,21 @@ +module cfromuint16 + +// +open System + +// Define a list of 16-bit unsigned integer values. +let values = + [ UInt16.MinValue; UInt16.MaxValue; 0xFFFus; 12345us; 40000us ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// 0 (UInt16) --> 0 (Decimal) +// 65535 (UInt16) --> 65535 (Decimal) +// 4095 (UInt16) --> 4095 (Decimal) +// 12345 (UInt16) --> 12345 (Decimal) +// 40000 (UInt16) --> 40000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromuint32.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint32.fs new file mode 100644 index 00000000000..78455a54915 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint32.fs @@ -0,0 +1,21 @@ +module cfromuint32 + +// +open System + +// Define a list of 32-bit unsigned integer values. +let values = + [ UInt32.MinValue; UInt32.MaxValue; 0xFFFFFFu; 123456789u; 4000000000u ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// 0 (UInt32) --> 0 (Decimal) +// 4294967295 (UInt32) --> 4294967295 (Decimal) +// 16777215 (UInt32) --> 16777215 (Decimal) +// 123456789 (UInt32) --> 123456789 (Decimal) +// 4000000000 (UInt32) --> 4000000000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/cfromuint64.fs b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint64.fs new file mode 100644 index 00000000000..a3578cd8898 --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/cfromuint64.fs @@ -0,0 +1,21 @@ +module cfromuint64 + +// +open System + +// Define a list of 64-bit unsigned integer values. +let values = + [ UInt64.MinValue; UInt64.MaxValue; 0xFFFFFFFFFFFFuL; 123456789123456789uL; 1000000000000000uL ] + +// Convert each value to a Decimal. +for value in values do + let decValue: decimal = value + printfn $"{value} ({value.GetType().Name}) --> {decValue} ({decValue.GetType().Name})" + +// The example displays the following output: +// 0 (UInt64) --> 0 (Decimal) +// 18446744073709551615 (UInt64) --> 18446744073709551615 (Decimal) +// 281474976710655 (UInt64) --> 281474976710655 (Decimal) +// 123456789123456789 (UInt64) --> 123456789123456789 (Decimal) +// 1000000000000000 (UInt64) --> 1000000000000000 (Decimal) +// \ No newline at end of file diff --git a/snippets/fsharp/System/Decimal/op_Implicit/fs.fsproj b/snippets/fsharp/System/Decimal/op_Implicit/fs.fsproj new file mode 100644 index 00000000000..a2af61f62ce --- /dev/null +++ b/snippets/fsharp/System/Decimal/op_Implicit/fs.fsproj @@ -0,0 +1,16 @@ + + + Exe + net6.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/xml/System/Decimal.xml b/xml/System/Decimal.xml index fc151a14f4f..a196e460523 100644 --- a/xml/System/Decimal.xml +++ b/xml/System/Decimal.xml @@ -115,12 +115,14 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/DecimalDivision_46630_1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/DecimalDivision_46630_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb" id="Snippet1"::: When the result of the division and multiplication is passed to the method, the result suffers no loss of precision, as the following code shows. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Class/cpp/decimal2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/DecimalDivision_46630_1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/DecimalDivision_46630_1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Class/vb/DecimalDivision_46630_1.vb" id="Snippet2"::: A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value. @@ -152,6 +154,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Decimal Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/source.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Decimal Example/VB/source.vb" id="Snippet1"::: ]]> @@ -240,6 +243,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Reals/CPP/ctordo.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctordo.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctordo.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Reals/VB/ctordo.vb" id="Snippet2"::: ]]> @@ -298,6 +302,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/CPP/ctori.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctori.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctori.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/VB/ctori.vb" id="Snippet1"::: ]]> @@ -371,6 +376,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Arrays/CPP/ctoriarr.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctoriarr.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctoriarr.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Arrays/VB/ctoriarr.vb" id="Snippet1"::: ]]> @@ -431,6 +437,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/CPP/ctorl.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctorl.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctorl.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/VB/ctorl.vb" id="Snippet3"::: ]]> @@ -523,6 +530,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Reals/CPP/ctors.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctors.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctors.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Reals/VB/ctors.vb" id="Snippet1"::: ]]> @@ -587,6 +595,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/CPP/ctorui.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctorui.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctorui.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/VB/ctorui.vb" id="Snippet2"::: ]]> @@ -645,6 +654,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/CPP/ctorul.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctorul.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctorul.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Ints/VB/ctorul.vb" id="Snippet4"::: ]]> @@ -711,11 +721,13 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Ctor.Arrays/CPP/ctoriiibby.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctoriiibby.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctoriiibby.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ctor.Arrays/VB/ctoriiibby.vb" id="Snippet2"::: The following example uses the method to retrieve the component parts of an array. It then uses this array in the call to the constructor to instantiate a new value. :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctor2a.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctor2a.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.ctor/vb/ctor2a.vb" id="Snippet1"::: ]]> @@ -782,6 +794,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Decimal Example/CPP/source.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/source.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/source.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Decimal Example/VB/source.vb" id="Snippet5"::: ]]> @@ -845,6 +858,7 @@ The following example illustrates the method and contrasts it with the method. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Ceiling/ceiling1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Ceiling/ceiling1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: ]]> @@ -932,6 +946,7 @@ The following example compares several values. Note that the first comparison indicates that the two values are equal despite the subtraction operation performed on the `value2` variable. This is because the type has 29 digits of precision, whereas a difference between these two values can be detected only with 30 digits of precision. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Compare/Compare1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Compare/Compare1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.Compare/vb/Compare1.vb" id="Snippet1"::: ]]> @@ -1129,6 +1144,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/CPP/cto_eq_obj.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/CompareTo/cto_eq_obj.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/CompareTo/cto_eq_obj.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/VB/cto_eq_obj.vb" id="Snippet1"::: ]]> @@ -1196,6 +1212,7 @@ The following example calls the method to divide a range of values by 22.1. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Divide/Divide1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Divide/Divide1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.Divide/vb/Divide1.vb" id="Snippet1"::: ]]> @@ -1290,6 +1307,7 @@ Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -1355,6 +1373,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/CPP/cto_eq_obj.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/CompareTo/cto_eq_obj.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/CompareTo/cto_eq_obj.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/VB/cto_eq_obj.vb" id="Snippet1"::: ]]> @@ -1363,6 +1382,7 @@ Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -1428,6 +1448,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/CPP/comp_equal.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/CompareTo/comp_equal.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/CompareTo/comp_equal.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Compare_Equals/VB/comp_equal.vb" id="Snippet2"::: ]]> @@ -1500,6 +1521,7 @@ The following example illustrates the method and contrasts it with the method. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Ceiling/ceiling1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Ceiling/ceiling1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: ]]> @@ -1556,6 +1578,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.OACurrency/CPP/fromoacurrency.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/FromOACurrency/fromoacurrency.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/FromOACurrency/fromoacurrency.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.OACurrency/VB/fromoacurrency.vb" id="Snippet2"::: ]]> @@ -1634,11 +1657,13 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Get_Bits_Hash_Type/CPP/getbits.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/GetBits/getbits.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/GetBits/getbits.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Get_Bits_Hash_Type/VB/getbits.vb" id="Snippet2"::: The following example uses the method to retrieve the component parts of an array. It then uses this array in the call to the constructor to instantiate a new value. :::code language="csharp" source="~/snippets/csharp/System/Decimal/.ctor/ctor2a.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/.ctor/ctor2a.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.ctor/vb/ctor2a.vb" id="Snippet1"::: ]]> @@ -1776,6 +1801,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Get_Bits_Hash_Type/CPP/gettypecode.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/GetBits/gettypecode.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/GetBits/gettypecode.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Get_Bits_Hash_Type/VB/gettypecode.vb" id="Snippet3"::: ]]> @@ -1832,6 +1858,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Decimal Example/CPP/source.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/source.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/source.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Decimal Example/VB/source.vb" id="Snippet2"::: ]]> @@ -1887,6 +1914,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Fields/CPP/fields.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/MinusOne/fields.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/MinusOne/fields.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Fields/VB/fields.vb" id="Snippet1"::: ]]> @@ -1947,6 +1975,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Fields/CPP/fields.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/MinusOne/fields.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/MinusOne/fields.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Fields/VB/fields.vb" id="Snippet1"::: ]]> @@ -2015,6 +2044,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Mul_Div_Rem/CPP/mul_div_rem.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Multiply/mul_div_rem.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Multiply/mul_div_rem.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Mul_Div_Rem/VB/mul_div_rem.vb" id="Snippet1"::: ]]> @@ -2079,6 +2109,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Flr_Neg_Rnd_Trnc/CPP/floor_neg_trunc.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Negate/floor_neg_trunc.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Negate/floor_neg_trunc.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Flr_Neg_Rnd_Trnc/VB/floor_neg_trunc.vb" id="Snippet1"::: ]]> @@ -2130,6 +2161,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Fields/CPP/fields.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/MinusOne/fields.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/MinusOne/fields.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Fields/VB/fields.vb" id="Snippet1"::: ]]> @@ -2197,6 +2229,7 @@ The method defines the operation of the addition operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/addition1.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/addition1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/addition1.vb" id="Snippet3"::: If the language you're using doesn't support custom operators, call the method instead. @@ -2256,6 +2289,7 @@ The method defines the operation of the decrement operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/decrement1.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/decrement1.fs" id="Snippet4"::: Some languages (such as Visual Basic) that lack an increment operator can call the method directly, as the following example shows. @@ -2264,6 +2298,7 @@ If your language does not support custom operators, call the method instead, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/decrement2.cs" interactive="try-dotnet" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/decrement2.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/decrement2.vb" id="Snippet6"::: ]]> @@ -2329,6 +2364,7 @@ The method defines the operation of the division operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/division1.cs" interactive="try-dotnet" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/division1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/division1.vb" id="Snippet7"::: If the language you're using doesn't support custom operators, call the method instead. @@ -2399,6 +2435,7 @@ The method defines the operation of the equality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/equality1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/equality1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/equality1.vb" id="Snippet1"::: If the language you're using doesn't support custom operators, call the method instead. @@ -2476,6 +2513,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctos_byte.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctos_byte.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctos_byte.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctos_byte.vb" id="Snippet4"::: ]]> @@ -2538,6 +2576,7 @@ The following example converts numbers to values (Unicode characters) by using the explicit to conversion operator. :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctochar.cs" interactive="try-dotnet" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctochar.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctochar.vb" id="Snippet6"::: ]]> @@ -2603,6 +2642,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctosgl_dbl.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctosgl_dbl.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctosgl_dbl.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctosgl_dbl.vb" id="Snippet5"::: ]]> @@ -2665,6 +2705,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int16.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int16.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int16.vb" id="Snippet3"::: ]]> @@ -2728,6 +2769,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int32.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int32.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int32.vb" id="Snippet2"::: ]]> @@ -2790,6 +2832,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int64.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int64.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int64.vb" id="Snippet1"::: ]]> @@ -2861,6 +2904,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.decimal.operators.explicit/cpp/tosbyte.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/tosbyte.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/tosbyte.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators.explicit/vb/tosbyte.vb" id="Snippet1"::: ]]> @@ -2927,6 +2971,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.decimal.operators.explicit/cpp/tosingle1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/tosingle1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/tosingle1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators.explicit/vb/tosingle1.vb" id="Snippet2"::: ]]> @@ -2996,6 +3041,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int16.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int16.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int16.vb" id="Snippet3"::: ]]> @@ -3067,6 +3113,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int32.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int32.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int32.vb" id="Snippet2"::: ]]> @@ -3139,6 +3186,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvTo/CPP/ctou_int64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/ctou_int64.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/ctou_int64.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvTo/VB/ctou_int64.vb" id="Snippet1"::: ]]> @@ -3199,6 +3247,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/CPP/cfromdouble.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/cfromdouble.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/cfromdouble.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/VB/cfromdouble.vb" id="Snippet2"::: ]]> @@ -3262,6 +3311,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/CPP/cfromsingle.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/cfromsingle.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/cfromsingle.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/VB/cfromsingle.vb" id="Snippet3"::: ]]> @@ -3333,6 +3383,7 @@ The method defines the operation of the greater than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/greaterthan1.cs" interactive="try-dotnet" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/greaterthan1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/greaterthan1.vb" id="Snippet8"::: Languages that do not support custom operators can call the method instead. They may also be able to call the method directly, as the following example shows. @@ -3402,6 +3453,7 @@ The method defines the operation of the greater than or equal operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/greaterthanorequal1.cs" interactive="try-dotnet" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/greaterthanorequal1.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/greaterthanorequal1.vb" id="Snippet10"::: Languages that do not support custom operators can call the method instead. They may also be able to call the method directly, as the following example shows. @@ -3487,6 +3539,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/CPP/cfrombyte.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfrombyte.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfrombyte.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/VB/cfrombyte.vb" id="Snippet4"::: ]]> @@ -3548,6 +3601,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/CPP/cfromchar.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Explicit/cfromchar.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Explicit/cfromchar.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.Others/VB/cfromchar.vb" id="Snippet1"::: ]]> @@ -3609,6 +3663,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/CPP/cfromint16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromint16.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromint16.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/VB/cfromint16.vb" id="Snippet3"::: ]]> @@ -3670,6 +3725,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/CPP/cfromint32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromint32.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromint32.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/VB/cfromint32.vb" id="Snippet2"::: ]]> @@ -3731,6 +3787,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/CPP/cfromint64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromint64.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromint64.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/VB/cfromint64.vb" id="Snippet1"::: ]]> @@ -3800,6 +3857,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/CPP/cfromsbyte.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromsbyte.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromsbyte.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.SInts/VB/cfromsbyte.vb" id="Snippet4"::: ]]> @@ -3869,6 +3927,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/CPP/cfromuint16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromuint16.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromuint16.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/VB/cfromuint16.vb" id="Snippet3"::: ]]> @@ -3938,6 +3997,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/CPP/cfromuint32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromuint32.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromuint32.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/VB/cfromuint32.vb" id="Snippet2"::: ]]> @@ -4007,6 +4067,7 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/CPP/cfromuint64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Implicit/cfromuint64.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Implicit/cfromuint64.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.ConvFrom.UInts/VB/cfromuint64.vb" id="Snippet1"::: ]]> @@ -4063,6 +4124,7 @@ The method defines the operation of the increment operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/increment1.cs" interactive="try-dotnet" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/increment1.fs" id="Snippet12"::: Some languages (such as Visual Basic) that lack an increment operator can call the method directly, as the following example shows. @@ -4071,6 +4133,7 @@ If your language does not support custom operators, call the method instead, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/increment2.cs" interactive="try-dotnet" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/increment2.fs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/increment2.vb" id="Snippet14"::: ]]> @@ -4137,6 +4200,7 @@ The method defines the operation of the inequality operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/inequality1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/inequality1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/inequality1.vb" id="Snippet2"::: If the language you're using doesn't support custom operators, you can test for inequality by using one of the following techniques: @@ -4209,6 +4273,7 @@ The method defines the operation of the less than operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/lessthan1.cs" interactive="try-dotnet" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/lessthan1.fs" id="Snippet15"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/lessthan1.vb" id="Snippet15"::: Languages that do not support custom operators can call the method instead. They may also be able to call the method directly, as the following example shows. @@ -4278,6 +4343,7 @@ The method defines the operation of the less than or equal operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/lessthanorequal1.cs" interactive="try-dotnet" id="Snippet17"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/lessthanorequal1.fs" id="Snippet17"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/lessthanorequal1.vb" id="Snippet17"::: Languages that do not support custom operators can call the method instead. They may also be able to call the method directly, as the following example shows. @@ -4340,6 +4406,7 @@ The operator defines the remainder operation that returns the remainder resulting from dividing two specified values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/modulus1.cs" interactive="try-dotnet" id="Snippet19"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/modulus1.fs" id="Snippet19"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/modulus1.vb" id="Snippet19"::: The sign of the value returned by the remainder operation depends on the sign of dividend. If dividend is positive, the remainder operation returns a positive result; if it is negative, the remainder operation returns a negative result. @@ -4410,6 +4477,7 @@ The method defines the operation of the multiplication operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/multiply1.cs" interactive="try-dotnet" id="Snippet20"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/multiply1.fs" id="Snippet20"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/multiply1.vb" id="Snippet20"::: If the language you're using doesn't support custom operators, call the method instead. @@ -4477,6 +4545,7 @@ The method defines the operation of the subtraction operator for values. It enables code such as the following: :::code language="csharp" source="~/snippets/csharp/System/Decimal/op_Addition/subtraction1.cs" interactive="try-dotnet" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/op_Addition/subtraction1.fs" id="Snippet21"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.operators/vb/subtraction1.vb" id="Snippet21"::: If the language you're using doesn't support custom operators, call the method instead. @@ -4683,6 +4752,7 @@ The following code example uses the method to parse string representations of values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Parse/parse.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Parse/parse.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Parse/VB/parse.vb" id="Snippet1"::: ]]> @@ -4803,6 +4873,7 @@ The following code example uses the method to parse the string representations of values using the en-US culture. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Parse/parse.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Parse/parse.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Parse/VB/parse.vb" id="Snippet2"::: ]]> @@ -5066,6 +5137,7 @@ The following example uses a variety of `style` and `provider` parameters to parse the string representations of values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Parse/parse.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Parse/parse.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Parse/VB/parse.vb" id="Snippet3"::: ]]> @@ -5138,6 +5210,7 @@ The following example uses the method to calculate the remainder in a series of division operations. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Remainder/remainder.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Remainder/remainder.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.remainder/vb/remainder.vb" id="Snippet1"::: ]]> @@ -5204,6 +5277,7 @@ The following example rounds a range of values between 100 and 102 to the nearest integer. Because the method uses banker's rounding, 100.5 rounds to 100 and 101.5 rounds to 102. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/Round1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/Round1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Decimal.Round/vb/Round1.vb" id="Snippet1"::: ]]> @@ -5269,6 +5343,7 @@ This method is equivalent to calling the @@ -5337,6 +5412,7 @@ If you specify or method with different `mode` arguments. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/midpoint1.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/midpoint1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint1.vb" id="Snippet5"::: ]]> @@ -5407,6 +5483,7 @@ If you specify or method with the enumeration. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/mpr.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/mpr.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb" id="Snippet1"::: ]]> @@ -5477,6 +5554,7 @@ If you specify or @@ -6565,6 +6643,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToByte/tobyte_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToByte/tobyte_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.tobyte/vb/tobyte_1.vb" id="Snippet1"::: ]]> @@ -6637,6 +6716,7 @@ This member is an explicit interface member implementation. It can be used only :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.ToXXX/CPP/tosgl_dbl.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToDouble/tosgl_dbl.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToDouble/tosgl_dbl.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToXXX/VB/tosgl_dbl.vb" id="Snippet5"::: ]]> @@ -6698,6 +6778,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToInt16/toint16_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToInt16/toint16_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.toint16/vb/toint16_1.vb" id="Snippet1"::: ]]> @@ -6769,6 +6850,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToInt32/toint32_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToInt32/toint32_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.toint32/vb/toint32_1.vb" id="Snippet1"::: ]]> @@ -6840,6 +6922,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToInt64/toint64_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToInt64/toint64_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.toint64/vb/toint64_1.vb" id="Snippet1"::: ]]> @@ -6895,6 +6978,7 @@ This member is an explicit interface member implementation. It can be used only :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.OACurrency/CPP/tooacurrency.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/FromOACurrency/tooacurrency.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/FromOACurrency/tooacurrency.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.OACurrency/VB/tooacurrency.vb" id="Snippet1"::: ]]> @@ -6962,6 +7046,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToSByte/tosbyte1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToSByte/tosbyte1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.tosbyte/vb/tosbyte1.vb" id="Snippet1"::: ]]> @@ -7035,6 +7120,7 @@ This member is an explicit interface member implementation. It can be used only :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.ToXXX/CPP/tosgl_dbl.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToDouble/tosgl_dbl.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToDouble/tosgl_dbl.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToXXX/VB/tosgl_dbl.vb" id="Snippet5"::: ]]> @@ -7124,12 +7210,14 @@ This member is an explicit interface member implementation. It can be used only The following example displays a value using the default method. It also displays the string representations of the value that result from using a number of standard format specifiers. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToString/ToString2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToString/ToString2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet2"::: The following example displays the amount of money in an account. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Decimal Example/CPP/source.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Overview/source.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Overview/source.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Decimal Example/VB/source.vb" id="Snippet5"::: ]]> @@ -7221,6 +7309,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays the string representation of a value using objects that represent several different cultures. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToString/ToString2.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToString/ToString2.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet3"::: ]]> @@ -7307,6 +7396,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a value using each of the supported standard numeric format specifiers, together with two custom numeric format strings. In converting the numeric values to strings, the example uses the formatting conventions of the en-US culture. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToString/ToString2.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToString/ToString2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet4"::: ]]> @@ -7402,6 +7492,7 @@ This member is an explicit interface member implementation. It can be used only The following example displays a value using each of the supported standard numeric format specifiers for several different cultures. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToString/ToString2.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToString/ToString2.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.ToString/VB/ToString2.vb" id="Snippet5"::: ]]> @@ -7477,6 +7568,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToUInt16/touint16_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToUInt16/touint16_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.touint16/vb/touint16_1.vb" id="Snippet1"::: ]]> @@ -7553,6 +7645,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToUInt32/touint32_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToUInt32/touint32_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.touint32/vb/touint32_1.vb" id="Snippet1"::: ]]> @@ -7629,6 +7722,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert decimal numbers to values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/ToUInt64/touint64_1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/ToUInt64/touint64_1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.touint64/vb/touint64_1.vb" id="Snippet1"::: ]]> @@ -7699,6 +7793,7 @@ This member is an explicit interface member implementation. It can be used only :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Flr_Neg_Rnd_Trnc/CPP/floor_neg_trunc.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/Negate/floor_neg_trunc.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Negate/floor_neg_trunc.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Flr_Neg_Rnd_Trnc/VB/floor_neg_trunc.vb" id="Snippet1"::: ]]> @@ -7933,6 +8028,7 @@ This member is an explicit interface member implementation. It can be used only The following example uses the method to convert the string representations of numeric values to values. It assumes that en-US is the current culture. :::code language="csharp" source="~/snippets/csharp/System/Decimal/TryParse/TryParse.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/TryParse/TryParse.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.TryParse/vb/TryParse.vb" id="Snippet1"::: ]]> @@ -8079,6 +8175,7 @@ This member is an explicit interface member implementation. It can be used only The following example demonstrates the use of the method to parse the string representation of a number that has a particular style and is formatted using the conventions of a particular culture. :::code language="csharp" source="~/snippets/csharp/System/Decimal/TryParse/TryParse.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/TryParse/TryParse.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.TryParse/vb/TryParse.vb" id="Snippet2"::: ]]> @@ -8139,6 +8236,7 @@ This member is an explicit interface member implementation. It can be used only :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Decimal.Fields/CPP/fields.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Decimal/MinusOne/fields.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/MinusOne/fields.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Decimal.Fields/VB/fields.vb" id="Snippet1"::: ]]>