C# Double Parse(String, IFormatProvider)

Description

Double Parse(String, IFormatProvider) converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent.

Syntax

Double.Parse(String, IFormatProvider) has the following syntax.


public static double Parse(
  string s,
  IFormatProvider provider
)

Parameters

Double.Parse(String, IFormatProvider) has the following parameters.

  • s - A string that contains a number to convert.
  • provider - An object that supplies culture-specific formatting information about s.

Returns

Double.Parse(String, IFormatProvider) method returns A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s.

Example

The NumberFormatInfo object that belongs to that CultureInfo object is passed to the Parse(String, IFormatProvider) method to convert the user's input to a Double value.


using System;//from  ww w. ja  va 2s.co  m
using System.Globalization;
public class MainClass
{
    public static void Main(String[] argv)
    {
        double number;
        try
        {
            number = Double.Parse("123", CultureInfo.InvariantCulture.NumberFormat);
        }
        catch (FormatException)
        {
            return;
        }
        catch (Exception)
        {
            return;
        }

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version