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.