Parse string with currency symbol to byte in CSharp
Description
The following code shows how to parse string with currency symbol to byte.
Example
using System;// www . j a v a 2 s. co m
using System.Globalization;
public class SByteConversion
{
NumberFormatInfo provider = NumberFormatInfo.CurrentInfo;
public static void Main()
{
string stringValue;
NumberStyles style;
stringValue = "$100";
style = NumberStyles.AllowCurrencySymbol;
CallParseOperation(stringValue, style);
}
private static void CallParseOperation(string stringValue, NumberStyles style)
{
sbyte number;
try
{
number = sbyte.Parse(stringValue, style);
Console.WriteLine("SByte.Parse('{0}', {1})) = {2}",stringValue, style.ToString(), number);
}
catch (Exception e)
{
Console.WriteLine("'{0}' and {1} throw a {2}", stringValue, style.ToString(), e.GetType().Name);
}
}
}
The code above generates the following result.