Parse string with decimal point to byte in CSharp
Description
The following code shows how to parse string with decimal point to byte.
Example
using System;//from w w w . java 2s . c o m
using System.Globalization;
public class SByteConversion
{
NumberFormatInfo provider = NumberFormatInfo.CurrentInfo;
public static void Main()
{
string stringValue;
NumberStyles style;
style = NumberStyles.AllowDecimalPoint;
CallParseOperation("100.0", 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.