Double - ToMoney

A Double extension method that converts the @this to a money.

Try it

public static void Main()
{
    double[] values = { 32.7865, 7.03, 7.64, 0.12, -0.12, -7.1, -7.6, -32.9012 };

    Console.WriteLine("  Value          Money\n");
    foreach (decimal value in values)
    {
		// C# Extension Method: Double - ToMoney
        Console.WriteLine("{0,7} {1,16}", value, value.ToMoney());
    }
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     A Double extension method that converts the @this to a money.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>@this as a Double.</returns>
    public static Double ToMoney(this Double @this)
    {
        return Math.Round(@this, 2);
    }
}