C# Convert ToDecimal(Int32)

Description

Convert ToDecimal(Int32) converts the value of the specified 32-bit signed integer to an equivalent decimal number.

Syntax

Convert.ToDecimal(Int32) has the following syntax.


public static decimal ToDecimal(
  int value
)

Parameters

Convert.ToDecimal(Int32) has the following parameters.

  • value - The 32-bit signed integer to convert.

Returns

Convert.ToDecimal(Int32) method returns A decimal number that is equivalent to value.

Example

The following example converts an array of signed integers to Decimal values.


//w  w w  . j  a v  a 2s .  co m
using System;
public class MainClass{
  public static void Main(String[] argv){  
    int[] numbers = { Int32.MinValue, -1000, 0, 1000, Int32.MaxValue };
    decimal result;
    
    foreach (int number in numbers)
    {
       result = Convert.ToDecimal(number);
       Console.WriteLine("Converted the Int32 value {0} to the Decimal value {1}.",
                         number, result);
    }

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version