REFERENCE :- https://docs.microsoft.com/en-us/dotnet/api/system.single.parse?view=net-6.0
if input is (123) than output will be 123
using System;
public class Example
{
public static void Main()
{
string[] values = { "123", "(123)", "-123,456,789", "123.45e+6",
"+543", "5e2", "3.1416", "600.", "-.123",
"-Infinity", "-1E-16", Double.MaxValue.ToString(),
Single.MinValue.ToString(), String.Empty };
foreach (string value in values)
{
try {
float number = Single.Parse(value);
Console.WriteLine("{0} -> {1}", value, number);
}
catch (FormatException) {
Console.WriteLine("'{0}' is not in a valid format.", value);
}
catch (OverflowException) {
Console.WriteLine("{0} is outside the range of a Single.", value);
}
}
}
}
// Output will be as below
No comments:
Post a Comment