Try to parse a string with currency symbol and a thousands separator to float in CSharp
Description
The following code shows how to try to parse a string with currency symbol and a thousands separator to float.
Example
using System;/*from ww w . ja va 2 s.c om*/
using System.Globalization;
public class Example
{
public static void Main()
{
string value;
float number;
value = "$1,234.56";
if (Single.TryParse(value, out number))
Console.WriteLine(number);
else
Console.WriteLine("Unable to parse '{0}'.", value);
}
}
The code above generates the following result.