Convert Decimal to int in CSharp
Description
The following code shows how to convert Decimal to int.
Example
/* w ww .j a v a2 s.c o m*/
using System;
class MainClass
{
public static void DecimalToU_Int16( decimal argument )
{
object Int16Value = null;
object UInt16Value = null;
try
{
Int16Value = decimal.ToInt16( argument );
}
catch( Exception ex )
{
Int16Value = null;
}
try
{
UInt16Value = decimal.ToUInt16( argument );
}
catch( Exception ex )
{
UInt16Value = null;
}
Console.WriteLine( Int16Value);
Console.WriteLine( UInt16Value );
}
public static void Main( )
{
DecimalToU_Int16( 123M );
}
}
The code above generates the following result.