Decimal - ToSingle

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

Try it

static string formatter = "{0,30}{1,23}";

public static void Display(Decimal val)
{
    // C# Extension Method: Decimal - ToSingle
    var SingleValue = val.ToSingle();

    Console.WriteLine(formatter, val, SingleValue);
}

public static void Main()
{
    Console.WriteLine(formatter, "Decimal value", "float");
    Console.WriteLine(formatter, "-------------", "------");

    // Convert decimal values and display the results.
    Display(0.0000000000000000000000000001M);
    Display(0.0000000000123456789123456789M);
    Display(123M);
    Display(new decimal(123000000, 0, 0, false, 6));
    Display(123456789.123456789M);
    Display(123456789123456789123456789M);
    Display(decimal.MinValue);
    Display(decimal.MaxValue);
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Converts the value of the specified  to the equivalent single-precision floating-point number.
    /// </summary>
    /// <param name="d">The decimal number to convert.</param>
    /// <returns>A single-precision floating-point number equivalent to the value of .</returns>
    public static Single ToSingle(this Decimal d)
    {
        return Decimal.ToSingle(d);
    }
}