Decimal - ToUInt64

Converts the value of the specified to the equivalent 64-bit unsigned integer.

Try it

static string formatter = "{0,30}{1,23}";
public static void Main()
{
    decimal[] values = { 123m, new Decimal(123000, 0, 0, false, 3), 
                       123.999m, 18446744073709551615.999m, 
                       18446744073709551616m, 9223372036854775807.999m, 
                       9223372036854775808m, -0.999m, -1m, 
                       -9223372036854775808.999m, 
                       -9223372036854775809m };
	
	Console.WriteLine(formatter, "Decimal value", "UInt64");
    Console.WriteLine(formatter, "----------------", "------");

    foreach (var value in values)
    {
        try
        {
			// C# Extension Method: Decimal - ToUInt64
            ulong number = value.ToUInt64();
            Console.WriteLine(formatter, value, number);
        }
        catch (OverflowException e)
        {
            Console.WriteLine(formatter, e.GetType().Name, value);
        }
    }
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Converts the value of the specified  to the equivalent 64-bit unsigned integer.
    /// </summary>
    /// <param name="d">The decimal number to convert.</param>
    /// <returns>A 64-bit unsigned integer equivalent to the value of .</returns>
    public static UInt64 ToUInt64(this Decimal d)
    {
        return Decimal.ToUInt64(d);
    }
}