Try to Parse string exponential notation to float in CSharp

Description

The following code shows how to try to Parse string exponential notation to float.

Example


using System;//from   www. j a  v  a2 s . co  m
using System.Globalization;

public class Example
{
    public static void Main()
    {

        string value;
        float number;

        value = "-1.2345e6";
        if (Single.TryParse(value, out number))
           Console.WriteLine(number);
        else
           Console.WriteLine("Unable to parse '{0}'.", value);   
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var