• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET Decimal.Explicit操作符代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Decimal.Explicit操作符的典型用法代码示例。如果您正苦于以下问题:VB.NET Decimal.Explicit操作符的具体用法?VB.NET Decimal.Explicit怎么用?VB.NET Decimal.Explicit使用的例子?那么恭喜您, 这里精选的操作符代码示例或许可以为您提供帮助。您也可以进一步了解该操作符所在System.Decimal的用法示例。



在下文中一共展示了Decimal.Explicit操作符的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: DecimalFromSingleDemo

' Example of the explicit conversion from Single to Decimal.
Module DecimalFromSingleDemo

    Const formatter As String = "{0,16:E7}{1,33}"
 
    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception ) As String

        Dim exceptionType   As String = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1 )
    End Function

    ' Convert the Single argument; catch exceptions that are thrown.
    Sub DecimalFromSingle( argument As Single )

        Dim decValue    As Object
          
        ' Convert the Single argument to a Decimal value.
        Try
            decValue = Decimal.op_Explicit( argument )
        Catch ex As Exception
            decValue = GetExceptionType( ex )
        End Try

        ' Display the Decimal.
        Console.WriteLine( formatter, argument, decValue )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the explicit conversion from Single " & _
            "to Decimal " & vbCrLf & "generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Single argument", _
            "Decimal value" )
        Console.WriteLine( formatter, "---------------", _
            "-------------" )
          
        ' Convert Single values and display the results.
        DecimalFromSingle( 1.2345E-30 )
        DecimalFromSingle( 1.2345E-26 )
        DecimalFromSingle( 1.23456E-22 )
        DecimalFromSingle( 1.23456E-12 )
        DecimalFromSingle( 1.234567 )
        DecimalFromSingle( 1.234567E+12 )
        DecimalFromSingle( 1.2345678E+28 ) 
        DecimalFromSingle( 1.2345678E+30 )
    End Sub 
End Module

' This example of the explicit conversion from Single to Decimal
开发者ID:VB.NET开发者,项目名称:System,代码行数:53,代码来源:Decimal.Explicit

输出:

Single 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


示例2: DecimalFromDoubleDemo

' Example of the explicit conversion from Double to Decimal.
Module DecimalFromDoubleDemo

    Const formatter As String = "{0,25:E16}{1,33}"
 
    ' Get the exception type name; remove the namespace prefix.
    Function GetExceptionType( ex As Exception ) As String

        Dim exceptionType   As String = ex.GetType( ).ToString( )
        Return exceptionType.Substring( _
            exceptionType.LastIndexOf( "."c ) + 1 )
    End Function

    ' Convert the Double argument; catch exceptions that are thrown.
    Sub DecimalFromDouble( argument As Double )

        Dim decValue    As Object
          
        ' Convert the Double argument to a Decimal value.
        Try
            decValue = Decimal.op_Explicit( argument )
        Catch ex As Exception
            decValue = GetExceptionType( ex )
        End Try

        ' Display the Decimal.
        Console.WriteLine( formatter, argument, decValue )
    End Sub 
       
    Sub Main( )

        Console.WriteLine( _
            "This example of the explicit conversion from Double " & _
            "to Decimal " & vbCrLf & "generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Double argument", _
            "Decimal value" )
        Console.WriteLine( formatter, "---------------", _
            "-------------" )
          
        ' 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 )
    End Sub 
End Module

' This example of the explicit conversion from Double to Decimal
开发者ID:VB.NET开发者,项目名称:System,代码行数:53,代码来源:Decimal.Explicit

输出:

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


示例3: Main

' Example of the explicit conversions from Decimal to Integer and 
' Decimal to UInteger.
Module DecimalToU_Int32Demo

    Const formatter As String = "{0,17}{1,19}{2,19}"

    ' Convert the decimal argument catch exceptions that are thrown.
    Public Sub DecimalToU_Int32(argument As Decimal)
        Dim Int32Value As Object
        Dim UInt32Value As Object

        ' Convert the argument to an int value.
        Try
            Int32Value = CInt(argument)
        Catch ex As Exception 
            Int32Value = ex.GetType().Name
        End Try

        ' Convert the argument to a uint value.
        Try
            UInt32Value = CUInt(argument)
        Catch ex As Exception
            UInt32Value = ex.GetType().Name
        End Try

        Console.WriteLine(formatter, argument, _
            Int32Value, UInt32Value)
    End Sub

    Public Sub Main( )
        Console.WriteLine( formatter, "Decimal Argument", _ 
            "Integer/Exception", "UInteger/Exception" )
        Console.WriteLine( formatter, "----------------", _ 
            "-------------", "--------------" )

        ' Convert decimal values and display the results.
        DecimalToU_Int32( 123d)
        DecimalToU_Int32(New Decimal(123000, 0, 0, False, 3))
        DecimalToU_Int32(123.999d)
        DecimalToU_Int32(4294967295.999d)
        DecimalToU_Int32(4294967296d)
        DecimalToU_Int32(2147483647.999d)
        DecimalToU_Int32(2147483648d)
        DecimalToU_Int32(-0.999d)
        DecimalToU_Int32(-1d)
        DecimalToU_Int32(-2147483648.999d)
        DecimalToU_Int32(-2147483649d)
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:49,代码来源:Decimal.Explicit

输出:

Decimal Argument  Integer/Exception UInteger/Exception
----------------      -------------     --------------
123                123                123
123.000                123                123
123.999                124                124
4294967295.999  OverflowException  OverflowException
4294967296  OverflowException  OverflowException
2147483647.999  OverflowException         2147483648
2147483648  OverflowException         2147483648
-0.999                 -1  OverflowException
-1                 -1  OverflowException
-2147483648.999  OverflowException  OverflowException
-2147483649  OverflowException  OverflowException


示例4: Main

' Example of the explicit conversions from Decimal to Short and 
' Decimal to UShort.
Module DecimalToU_Int16Demo

    Const formatter As String = "{0,16}{1,19}{2,19}"

    ' Convert the decimal argument and catch exceptions that are thrown.
    Public Sub DecimalToU_Int16(argument As Decimal)
        Dim Int16Value As Object
        Dim UInt16Value As Object

        ' Convert the argument to a Short value.
        Try
            Int16Value = CShort(argument)
        Catch ex As Exception 
            Int16Value = ex.GetType().Name
        End Try

        ' Convert the argument to a UShort value.
        Try
            UInt16Value = CUShort(argument)
        Catch ex As Exception
            UInt16Value = ex.GetType().Name
        End Try

        Console.WriteLine( formatter, argument, _
            Int16Value, UInt16Value )
    End Sub

    Public Sub Main( )
        Console.WriteLine( formatter, "Decimal argument", _ 
            "Short/Exception", "UShort/Exception" )
        Console.WriteLine( formatter, "----------------", _ 
            "---------------", "----------------" )

        ' Convert decimal values and display the results.
        DecimalToU_Int16(123d)
        DecimalToU_Int16(New Decimal( 123000, 0, 0, False, 3 ))
        DecimalToU_Int16(123.999d)
        DecimalToU_Int16(65535.999d)
        DecimalToU_Int16(65536d)
        DecimalToU_Int16(32767.999d)
        DecimalToU_Int16(32768d)
        DecimalToU_Int16(-0.999d)
        DecimalToU_Int16(-1d)
        DecimalToU_Int16(-32768.999d)
        DecimalToU_Int16(-32769d)
    End Sub
End Module
' This example displays the following output to the console:
'    Decimal argument    Short/Exception   UShort/Exception
'    ----------------    ---------------   ----------------
'                 123                123                123
'             123.000                123                123
'             123.999                124                124
'           65535.999  OverflowException  OverflowException
'               65536  OverflowException  OverflowException
'           32767.999  OverflowException              32768
'               32768  OverflowException              32768
'              -0.999                 -1  OverflowException
'                  -1                 -1  OverflowException
'          -32768.999  OverflowException  OverflowException
'              -32769  OverflowException  OverflowException
开发者ID:VB.NET开发者,项目名称:System,代码行数:63,代码来源:Decimal.Explicit


示例5: Main

Module Example
    Public Sub Main( )
        ' Define an array of Decimal values.
        Dim values() As Decimal= { 0.0000000000000000000000000001d, 
                                   0.0000000000123456789123456789d,
                                   123d, 
                                   New Decimal(123000000, 0, 0, False, 6),
                                   123456789.123456789d, 
                                   123456789123456789123456789d, 
                                   Decimal.MinValue, Decimal.MaxValue }
        For Each value In values
            Dim dblValue As Single = CSng(value)
            Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType().Name, dblValue, 
                              dblValue.GetType().Name)
        Next
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Decimal.Explicit

输出:

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)


示例6: Main

Option Strict On

Module Example
    Public Sub Main()
        ' Define an array of decimal values.
        Dim values() As Decimal = { 78d, New Decimal(78000, 0, 0, False, 3),
                                    78.999d, 255.999d, 256d, 127.999d,
                                    128d, -0.999d, -1d, -128.999d, 
                                    -129d }           
        For Each value In values
           Try
              Dim byteValue As SByte = CSByte(value)
              Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                                value.GetType().Name, byteValue, 
                                byteValue.GetType().Name)
           Catch e As OverflowException
              Console.WriteLine("OverflowException: Cannot convert {0}",
                                value)
           End Try
        Next   
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:Decimal.Explicit

输出:

78 (Decimal) --> 78 (SByte)
78.000 (Decimal) --> 78 (SByte)
78.999 (Decimal) --> 79 (SByte)
OverflowException: Cannot convert 255.999
OverflowException: Cannot convert 256
OverflowException: Cannot convert 127.999
OverflowException: Cannot convert 128
-0.999 (Decimal) --> -1 (SByte)
-1 (Decimal) --> -1 (SByte)
OverflowException: Cannot convert -128.999
OverflowException: Cannot convert -129


示例7: Main

' Example of the explicit conversions from Decimal to Long and 
' Decimal to ULong.
Module DecimalToU_Int64Demo

    Const formatter As String = "{0,25}{1,22}{2,22}"

    ' Convert the decimal argument catch exceptions that are thrown.
    Public Sub DecimalToU_Int64(argument As Decimal)
        Dim Int64Value As Object
        Dim UInt64Value As Object

        ' Convert the argument to a long value.
        Try
            Int64Value = CLng(argument)
        Catch ex As Exception
            Int64Value = ex.GetType().Name
        End Try

        ' Convert the argument to a ulong value.
        Try
            UInt64Value = CULng(argument)
        Catch ex As Exception
            UInt64Value = ex.GetType().Name
        End Try

        Console.WriteLine(formatter, argument, _ 
            Int64Value, UInt64Value)
    End Sub

    Public Sub Main( )
        Console.WriteLine( formatter, "Decimal argument", _
            "Long/Exception", "ULong/Exception" )
        Console.WriteLine( formatter, "----------------", _
            "--------------", "---------------" )

        ' Convert decimal values and display the results.
        DecimalToU_Int64(123d)
        DecimalToU_Int64(New Decimal(123000, 0, 0, False, 3))
        DecimalToU_Int64(123.999d)
        DecimalToU_Int64(18446744073709551615.999d)
        DecimalToU_Int64(18446744073709551616d)
        DecimalToU_Int64(9223372036854775807.999d)
        DecimalToU_Int64(9223372036854775808d)
        DecimalToU_Int64(-0.999d)
        DecimalToU_Int64(-1d)
        DecimalToU_Int64(-9223372036854775808.999d)
        DecimalToU_Int64(-9223372036854775809d)
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:49,代码来源:Decimal.Explicit

输出:

Decimal argument        Long/Exception       ULong/Exception
----------------        --------------       ---------------
123                   123                   123
123.000                   123                   123
123.999                   124                   124
18446744073709551615.999     OverflowException     OverflowException
18446744073709551616     OverflowException     OverflowException
9223372036854775807.999     OverflowException   9223372036854775808
9223372036854775808     OverflowException   9223372036854775808
-0.999                    -1     OverflowException
-1                    -1     OverflowException
-9223372036854775808.999     OverflowException     OverflowException
-9223372036854775809     OverflowException     OverflowException


示例8: Main

Module Example
    Public Sub Main( )
        ' Define an array of Decimal values.
        Dim values() As Decimal= { 0.0000000000000000000000000001d, 
                                   0.0000000000123456789123456789d,
                                   123d, 
                                   New Decimal(123000000, 0, 0, False, 6),
                                   123456789.123456789d, 
                                   123456789123456789123456789d, 
                                   Decimal.MinValue, Decimal.MaxValue }
        For Each value In values
            Dim dblValue As Double = CDbl(value)
            Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                              value.GetType().Name, dblValue, 
                              dblValue.GetType().Name)
        Next
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Decimal.Explicit

输出:

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)


示例9: Main

Option Strict On

Module Example
    Public Sub Main()
        ' Define an array of decimal values.
        Dim values() As Decimal = { 78d, New Decimal(78000, 0, 0, False, 3),
                                    78.999d, 255.999d, 256d, 127.999d,
                                    128d, -0.999d, -1d, -128.999d, 
                                    -129d }           
        For Each value In values
           Try
              Dim byteValue As Byte = CByte(value)
              Console.WriteLine("{0} ({1}) --> {2} ({3})", value,
                                value.GetType().Name, byteValue, 
                                byteValue.GetType().Name)
           Catch e As OverflowException
              Console.WriteLine("OverflowException: Cannot convert {0}",
                                value)
           End Try
        Next   
    End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:22,代码来源:Decimal.Explicit

输出:

78 (Decimal) --> 78 (Byte)
78.000 (Decimal) --> 78 (Byte)
78.999 (Decimal) --> 79 (Byte)
OverflowException: Cannot convert 255.999
OverflowException: Cannot convert 256
127.999 (Decimal) --> 128 (Byte)
128 (Decimal) --> 128 (Byte)
OverflowException: Cannot convert -0.999
OverflowException: Cannot convert -1
OverflowException: Cannot convert -128.999
OverflowException: Cannot convert -129



注:本文中的System.Decimal.Explicit操作符示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Decimal.Implicit操作符代码示例发布时间:2022-05-24
下一篇:
VB.NET Decimal.Equality操作符代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap