Convert Decimal to long in CSharp

Description

The following code shows how to convert Decimal to long.

Example


  //w w  w .j  ava 2  s.co m
  
  
  
using System;

class MainClass
{
    public static void DecimalToU_Int64( decimal argument )
    {
        object Int64Value = null;
        object UInt64Value = null;

        // Convert the argument to a long value.
        try
        {
            Int64Value = decimal.ToInt64( argument );
        }
        catch( Exception ex )
        {
            Int64Value = null;
        }

        // Convert the argument to a ulong value.
        try
        {
            UInt64Value = decimal.ToUInt64( argument );
        }
        catch( Exception ex )
        {
            UInt64Value = null;
        }

        Console.WriteLine( Int64Value);
        Console.WriteLine( UInt64Value );
    }

    public static void Main( )
    {
        DecimalToU_Int64( 123M );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var