C# Decimal ToSingle

Description

Decimal ToSingle converts the value of the specified Decimal to the equivalent single-precision floating-point number.

Syntax

Decimal.ToSingle has the following syntax.


public static float ToSingle(
  decimal d
)

Parameters

Decimal.ToSingle has the following parameters.

  • d - The decimal number to convert.

Returns

Decimal.ToSingle method returns A single-precision floating-point number equivalent to the value of d.

Example

The following code example converts Decimal numbers to Single values using the ToSingle method.


using System;/* w  w  w .  j a v a  2s.c  o m*/

class MainClass
{

    public static void Main( )
    {
        object SingleValue;
        SingleValue = decimal.ToSingle( 0.0000000000123456789123456789M );

        Console.WriteLine( SingleValue );

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version