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


C# Decimal.ToSingle方法代码示例

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


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

示例1: DecimalToSgl_Dbl

// Example of the decimal.ToSingle and decimal.ToDouble methods.
using System;

class DecimalToSgl_DblDemo
{
    static string formatter = "{0,30}{1,17}{2,23}";

    // Convert the decimal argument; no exceptions are thrown.
    public static void DecimalToSgl_Dbl( decimal argument )
    {
        object SingleValue;
        object DoubleValue;

        // Convert the argument to a float value.
        SingleValue = decimal.ToSingle( argument );

        // Convert the argument to a double value.
        DoubleValue = decimal.ToDouble( argument );

        Console.WriteLine( formatter, argument, 
            SingleValue, DoubleValue );
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the \n" +
            "  decimal.ToSingle( decimal ) and \n" +
            "  decimal.ToDouble( decimal ) \nmethods " +
            "generates the following output. It \ndisplays " +
            "several converted decimal values.\n" );
        Console.WriteLine( formatter, "decimal argument", 
            "float", "double" );
        Console.WriteLine( formatter, "----------------", 
            "-----", "------" );

        // Convert decimal values and display the results.
        DecimalToSgl_Dbl( 0.0000000000000000000000000001M );
        DecimalToSgl_Dbl( 0.0000000000123456789123456789M );
        DecimalToSgl_Dbl( 123M );
        DecimalToSgl_Dbl( new decimal( 123000000, 0, 0, false, 6 ) );
        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
*/
开发者ID:.NET开发者,项目名称:System,代码行数:65,代码来源:Decimal.ToSingle


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