Convert the string to its Decimal equivalent in CSharp

Description

The following code shows how to convert the string to its Decimal equivalent.

Example


/*from ww w . jav  a2 s  .  c  o m*/
using System;
using System.Globalization;
using System.Threading;

class DecimalFieldsDemo
{
    public static void Main()
    {
        decimal number;
        CultureInfo culture = Thread.CurrentThread.CurrentCulture;

        try
        {
            number = Decimal.Parse("1.1", culture.NumberFormat);
            Console.WriteLine(number);
        }
        catch (FormatException)
        {
            return;
        }
        catch (Exception)
        {
            return;
        }
    }
}

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