当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Decimal.ToOACurrency方法代码示例

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


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

示例1: DecimalToOACurrencyDemo

' Example of the Decimal.ToOACurrency method. 
Module DecimalToOACurrencyDemo
    
    Const dataFmt As String = "{0,31}{1,27}"

    ' 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

    ' Display the Decimal.ToOACurrency parameter and the result 
    ' or exception.
    Sub ShowDecimalToOACurrency( Argument As Decimal )

        ' Catch the exception if ToOACurrency( ) throws one.
        Try
            Dim oaCurrency As Long = Decimal.ToOACurrency( Argument )
            Console.WriteLine( dataFmt, Argument, _
                oaCurrency )

        Catch ex As Exception
            Console.WriteLine( dataFmt, Argument, _
                GetExceptionType( ex ) )
        End Try
    End Sub

    Sub Main( )
        Console.WriteLine( "This example of the " & _
            "Decimal.ToOACurrency( ) method generates " & vbCrLf & _
            "the following output. It displays the argument as " & _
            "a Decimal " & vbCrLf & "and the OLE Automation " & _
            "Currency value as a Long." & vbCrLf )
        Console.WriteLine( dataFmt, "Argument", _
            "OA Currency or Exception" )
        Console.WriteLine( dataFmt, "--------", _
            "------------------------" )

        ' Convert Decimal values to OLE Automation Currency values.
        ShowDecimalToOACurrency( 0D )
        ShowDecimalToOACurrency( 1D )
        ShowDecimalToOACurrency( _
            Decimal.Parse( "1.0000000000000000000000000000" ) )
        ShowDecimalToOACurrency( 100000000000000D )
        ShowDecimalToOACurrency( _
            Decimal.Parse( "100000000000000.00000000000000" ) )
        ShowDecimalToOACurrency( 10000000000000000000000000000D )
        ShowDecimalToOACurrency( 0.000000000123456789D ) 
        ShowDecimalToOACurrency( 0.123456789D ) 
        ShowDecimalToOACurrency( 123456789D ) 
        ShowDecimalToOACurrency( 123456789000000000D ) 
        ShowDecimalToOACurrency( 4294967295D ) 
        ShowDecimalToOACurrency( 18446744073709551615D ) 
        ShowDecimalToOACurrency( -79.228162514264337593543950335D ) 
        ShowDecimalToOACurrency( -79228162514264.337593543950335D ) 
    End Sub
End Module 

' 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
开发者ID:VB.NET开发者,项目名称:System,代码行数:80,代码来源:Decimal.ToOACurrency


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