当前位置: 首页>>代码示例>>C#>>正文


C# Decimal.ToOACurrency方法代码示例

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


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

示例1: GetExceptionType

// Example of the decimal.ToOACurrency method. 
using System;

class DecimalToOACurrencyDemo
{
    const string dataFmt = "{0,31}{1,27}";

    // Get the exception type name; remove the namespace prefix.
    public static string GetExceptionType( Exception ex )
    {
        string exceptionType = ex.GetType( ).ToString( );
        return exceptionType.Substring( 
            exceptionType.LastIndexOf( '.' ) + 1 );
    }

    // Display the decimal.ToOACurrency parameter and the result 
    // or exception.
    public static void ShowDecimalToOACurrency( decimal Argument )
    {
        // Catch the exception if ToOACurrency( ) throws one.
        try
        {
            long oaCurrency = decimal.ToOACurrency( Argument );
            Console.WriteLine( dataFmt, Argument, oaCurrency );
        }
        catch( Exception ex )
        {
            Console.WriteLine( dataFmt, Argument, 
                GetExceptionType( ex ) );
        }
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the " +
            "decimal.ToOACurrency( ) method generates \nthe " +
            "following output. It displays the argument as a " +
            "decimal \nand the OLE Automation Currency value " +
            "as a long.\n" );
        Console.WriteLine( dataFmt, "Argument", 
            "OA Currency or Exception" );
        Console.WriteLine( 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
*/
开发者ID:.NET开发者,项目名称:System,代码行数:84,代码来源:Decimal.ToOACurrency


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