System.Double Structure

Assembly: Mscorlib.dll
Namespace: System
Summary
Represents a double-precision floating point number.
C# Syntax:
[Serializable]
public struct Double : IComparable, IFormattable, IConvertible
Thread Safety
This type is safe for multithreaded operations.
Remarks
The Double value type represents a double-precision 64-bit number with values ranging from negative 1.79769313486232e308 to positive 1.79769313486232e308, as well as positive or negative zero, Double.PositiveInfinity, Double.NegativeInfinity, and Not-a-Number ( Double.NaN).

Double complies with the IEC 60559:1989 (IEEE 754) standard for binary floating-point arithmetic.

Double provides methods to compare instances of this type, convert the value of an instance to its string representation, and convert the string representation of a number to an instance of this type.

For information about how format specification codes control the string representation of value types, see the conceptual topic at MSDN: formattingoverview.

This type implements interfaces IComparable, IFormattable, and IConvertible. Use the Convert class for conversions instead of this type's explicit interface member implementation of IConvertible.

When performing binary operations, if one of the operands is a Double, then the other operand is required to be an integral type or a floating-point type (Double or Single). Prior to performing the operation, if the other operand is not a Double, it is converted to Double, and the operation is performed using at least Double range and precision. If the operation produces a numeric result, the type of the result is Double.

The floating-point operators, including the assignment operators, do not throw exceptions. Instead, in exceptional situations, the result of a floating-point operation is zero, infinity, or NaN, as described below:

See also:
System Namespace

System.Double Member List:

Public Fields
Epsilon Represents the smallest positive Double greater than zero. This field is constant.
MaxValue Represents the largest possible value of a Double. This field is constant.
MinValue Represents the smallest possible value of a Double. This field is constant.
NaN Represents a value that is not a number (NaN). This field is constant.
NegativeInfinity Represents negative infinity. This field is constant.
PositiveInfinity Represents positive infinity. This field is constant.
Public Methods
CompareTo Compares this instance to a specified object and returns an indication of their relative values.
Equals Overridden:
Returns a value indicating whether this instance is equal to a specified object.
GetHashCode Overridden:
Returns the hash code for this instance.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
GetTypeCode Returns the TypeCode for value type Double.
IsInfinity Returns a value indicating whether the specified number evaluates to negative or positive infinity
IsNaN Returns a value indicating whether the specified number evaluates to a value that is not a number ( Double.NaN).
IsNegativeInfinity Returns a value indicating whether the specified number evaluates to negative infinity.
IsPositiveInfinity Returns a value indicating whether the specified number evaluates to positive infinity.
Parse Overloaded:
Parse(string s)

Converts the string representation of a number to its double-precision floating point number equivalent.
Parse Overloaded:
Parse(string s, IFormatProvider provider)

Converts the string representation of a number in a specified culture-specific format to its double-precision floating point number equivalent.
Parse Overloaded:
Parse(string s, NumberStyles style)

Converts the string representation of a number in a specified style to its double-precision floating point number equivalent.
Parse Overloaded:
Parse(string s, NumberStyles style, IFormatProvider provider)

Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.
ToString Overloaded:
ToString()

Overridden:
Converts the numeric value of this instance to its equivalent string representation.
ToString Overloaded:
ToString(IFormatProvider provider)

Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
ToString Overloaded:
ToString(string format)

Converts the numeric value of this instance to its equivalent string representation, using the specified format.
ToString Overloaded:
ToString(string format, IFormatProvider provider)

Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
TryParse Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Double Member Details

Field: Epsilon
Summary
Represents the smallest positive Double greater than zero. This field is constant.
C# Syntax:
public const double Epsilon;
Remarks
The value of this constant is 4.94065645841247e-324.

Two apparently equivalent floating point numbers might not compare equal because of differences in their least significant digits. For example, the C# expression, (double)1/3 == (double)0.33333 , does not compare equal because the division operation on the left-hand side has maximum precision while the constant on the right-hand side is only precise to the visible digits.

Instead, determine if the two sides of a comparison are close enough to equal for your purposes by comparing whether the absolute value of the difference between the left and right-hand sides is less than Epsilon.

See also:
Double.Parse

Return to top


Field: MaxValue
Summary
Represents the largest possible value of a Double. This field is constant.
C# Syntax:
public const double MaxValue;
Remarks
The value of this constant is positive 1.79769313486232e308.

Return to top


Field: MinValue
Summary
Represents the smallest possible value of a Double. This field is constant.
C# Syntax:
public const double MinValue;
Remarks
The value of this constant is negative 1.79769313486232e308.

Return to top


Field: NaN
Summary
Represents a value that is not a number (NaN). This field is constant.
C# Syntax:
public const double NaN;
Remarks
The value of this constant is the result of dividing zero by zero.

This constant is returned when the result of an operation is undefined.

Use Double.IsNaN to determine whether a value is not a number. It is not possible to determine whether a value is not a number by comparing it to another value equal to NaN.

See also:
Double.IsNaN

Return to top


Field: NegativeInfinity
Summary
Represents negative infinity. This field is constant.
C# Syntax:
public const double NegativeInfinity;
Remarks
The value of this constant is the result of dividing a negative number by zero.

This constant is returned when the result of an operation is less than Double.MinValue.

Use Double.IsNegativeInfinity to determine whether a value evaluates to negative infinity. It is not possible to determine whether a value evaluates to negative infinity by comparing it to another value equal to NegativeInfinity.

See also:
Double.IsNegativeInfinity | Double.IsInfinity | Double.PositiveInfinity

Return to top


Field: PositiveInfinity
Summary
Represents positive infinity. This field is constant.
C# Syntax:
public const double PositiveInfinity;
Remarks
The value of this constant is the result of dividing a positive number by zero.

This constant is returned when the result of an operation is greater than Double.MaxValue.

Use Double.IsPositiveInfinity to determine whether a value evaluates to positive infinity. It is not possible to determine whether a value evaluates to positive infinity by comparing it to another value equal to PositiveInfinity.

See also:
Double.IsPositiveInfinity | Double.IsInfinity | Double.NegativeInfinity

Return to top


Method: CompareTo(
   object value
)
Summary
Compares this instance to a specified object and returns an indication of their relative values.
C# Syntax:
public int CompareTo(
   object value
);
Parameters:

value

An object to compare, or null.

Return Value:
A signed number indicating the relative values of this instance and value.

Value Description
A negative integer This instance is less than value. -or- This instance is not a number ( Double.NaN) and value is a number.
Zero This instance is equal to value. -or- This instance and value are both Double.NaN, Double.PositiveInfinity, or Double.NegativeInfinity
A positive integer This instance is greater than value. -or- This instance is a number and value is not a number ( Double.NaN). -or- value is null.
Exceptions
Exception Type Condition
ArgumentException value is not a Double or null.
Remarks
Any instance of Double, regardless of its value, is considered greater than null.

The value parameter must be null or an instance of Double; otherwise, an exception is thrown.

This method is implemented to support the IComparable interface. Note that, although a Double.NaN is not considered to be equal to another Double.NaN (even itself), the IComparable interface requires that A.CompareTo(A) return zero.

See also:
Double.Equals

Return to top


Overridden Method: Equals(
   object obj
)
Summary
Returns a value indicating whether this instance is equal to a specified object.
C# Syntax:
public override bool Equals(
   object obj
);
Parameters:

obj

An object to compare with this instance.

Return Value:
true if obj is an instance of Double and equals the value of this instance; otherwise, false.
See also:
Double.CompareTo

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~Double();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetTypeCode()
Summary
Returns the TypeCode for value type Double.
C# Syntax:
public TypeCode GetTypeCode();
Return Value:
The enumerated constant, TypeCode.Double.
See also:
TypeCode

Return to top


Method: IsInfinity(
   double d
)
Summary
Returns a value indicating whether the specified number evaluates to negative or positive infinity
C# Syntax:
public static bool IsInfinity(
   double d
);
Parameters:

d

A double-precision floating point number.

Return Value:
true if d evaluates to Double.PositiveInfinity or Double.NegativeInfinity; otherwise, false.
Remarks
Floating-point operations return Double.PositiveInfinity or Double.NegativeInfinity to signal an overflow condition.
See also:
Double.IsPositiveInfinity | Double.IsNegativeInfinity | Double.PositiveInfinity | Double.NegativeInfinity

Return to top


Method: IsNaN(
   double d
)
Summary
Returns a value indicating whether the specified number evaluates to a value that is not a number ( Double.NaN).
C# Syntax:
public static bool IsNaN(
   double d
);
Parameters:

d

A double-precision floating point number.

Return Value:
true if d evaluates to Double.NaN; otherwise, false.
Remarks
Floating-point operations return Double.NaN to signal that that result of the operation is undefined. For example, dividing 0.0 by 0.0 results in Double.NaN.
See also:
Double.NaN

Return to top


Method: IsNegativeInfinity(
   double d
)
Summary
Returns a value indicating whether the specified number evaluates to negative infinity.
C# Syntax:
public static bool IsNegativeInfinity(
   double d
);
Parameters:

d

A double-precision floating point number.

Return Value:
true if d evaluates to Double.NegativeInfinity; otherwise, false.
Remarks
Floating-point operations return Double.NegativeInfinity to signal an overflow condition.
See also:
Double.IsInfinity | Double.IsPositiveInfinity | Double.PositiveInfinity | Double.NegativeInfinity

Return to top


Method: IsPositiveInfinity(
   double d
)
Summary
Returns a value indicating whether the specified number evaluates to positive infinity.
C# Syntax:
public static bool IsPositiveInfinity(
   double d
);
Parameters:

d

A double-precision floating point number.

Return Value:
true if d evaluates to Double.PositiveInfinity; otherwise, false.
Remarks
Floating-point operations return Double.PositiveInfinity to signal an overflow condition.
See also:
Double.IsInfinity | Double.IsNegativeInfinity | Double.PositiveInfinity | Double.NegativeInfinity

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Overloaded Method: Parse(
   string s
)
Summary
Converts the string representation of a number to its double-precision floating point number equivalent.
C# Syntax:
public static double Parse(
   string s
);
Parameters:

s

A string containinga number to convert.

Return Value:
A double-precision floating point number equivalent to the numeric value or symbol specified in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not a number in a valid format.
OverflowException s represents a number less than Double.MinValue or greater than Double.MaxValue.
Remarks
The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

ws A series of white space characters. sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' An uppercase or lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

This version of Parse uses the NumberStyles values, NumberStyles.Float and NumberStyles.AllowThousands, and the culture-specific NumberFormatInfo data associated with the current thread.

For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.

See also:
MSDN: formattingoverview | Double.ToString

Return to top


Overloaded Method: Parse(
   string s,
   IFormatProvider provider
)
Summary
Converts the string representation of a number in a specified culture-specific format to its double-precision floating point number equivalent.
C# Syntax:
public static double Parse(
   string s,
   IFormatProvider provider
);
Parameters:

s

A string containinga number to convert.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

Return Value:
A double-precision floating point number equivalent to the numeric value or symbol specified in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not a number in a valid format.
OverflowException s represents a number less than Double.MinValue or greater than Double.MaxValue.
Remarks
The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

ws A series of white space characters. sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' An uppercase or lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

This version of Parse uses the NumberStyles values, NumberStyles.Float and NumberStyles.AllowThousands, and the specified number format information. If provider is null or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.

For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.

See also:
MSDN: formattingoverview | Double.ToString

Return to top


Overloaded Method: Parse(
   string s,
   NumberStyles style
)
Summary
Converts the string representation of a number in a specified style to its double-precision floating point number equivalent.
C# Syntax:
public static double Parse(
   string s,
   NumberStyles style
);
Parameters:

s

A string containing a number to convert.

style

The combination of one or more NumberStyles constants that indicate the permitted format of s.

Return Value:
A double-precision floating point number equivalent to the numeric value or symbol specified in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not a number in a valid format.
OverflowException s represents a number less than Double.MinValue or greater than Double.MaxValue.
Remarks
The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

ws A series of white space characters. sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' An uppercase or lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

This version of Parse uses the specified NumberStyles and the culture-specific NumberFormatInfo data associated with the current thread.

For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.

See also:
MSDN: formattingoverview | Double.ToString

Return to top


Overloaded Method: Parse(
   string s,
   NumberStyles style,
   IFormatProvider provider
)
Summary
Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.
C# Syntax:
public static double Parse(
   string s,
   NumberStyles style,
   IFormatProvider provider
);
Parameters:

s

A string containinga number to convert.

style

The combination of one or more NumberStyles constants that indicate the permitted format of s.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

Return Value:
A double-precision floating point number equivalent to the numeric value or symbol specified in s.
Exceptions
Exception Type Condition
ArgumentNullException s is null.
FormatException s is not a numeric value.
ArgumentException style is not a combination of bit flags from the NumberStyles enumeration.
Remarks
The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

ws A series of white space characters. sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' An uppercase or lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

This version of Parse uses the specified NumberStyles and the specified number format information. If provider is null or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.

For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.

See also:
MSDN: formattingoverview | Double.ToString

Return to top


Overloaded Method: ToString()
Summary
Converts the numeric value of this instance to its equivalent string representation.
C# Syntax:
public override string ToString();
Return Value:
The string representation of the value of this instance.
Remarks
The return value can be NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' A lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".

This version of ToString uses the general format specifier ("G") and the NumberFormatInfo for the current culture.

See also:
MSDN: formattingoverview | Double.Parse | String

Return to top


Overloaded Method: ToString(
   IFormatProvider provider
)
Summary
Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
C# Syntax:
public string ToString(
   IFormatProvider provider
);
Parameters:

provider

An IFormatProvider that supplies culture-specific formatting information.

Return Value:
The string representation of the value of this instance as specified by provider.
Remarks
The return value can be NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' A lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".

This instance is formatted with the general format specifier ("G").

The provider parameter is an IFormatProvider instance that obtains a NumberFormatInfo object that supplies culture-specific format information. If provider is null, the return value is formatted with NumberFormatInfo data for the current culture.

See also:
MSDN: formattingoverview | Double.Parse | String

Return to top


Overloaded Method: ToString(
   string format
)
Summary
Converts the numeric value of this instance to its equivalent string representation, using the specified format.
C# Syntax:
public string ToString(
   string format
);
Parameters:

format

A format string.

Return Value:
The string representation of the value of this instance as specified by format.
Exceptions
Exception Type Condition
FormatException format is invalid.
Remarks
The return value can be NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' A lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".

If format is null or an empty string, the return value is formatted with the general format specifier ("G").

By default, the return value only contains 15 digits of precision although a maximum of 17 digits is maintained internally. If the value of this instance has greater than 15 digits, ToString returns NumberFormatInfo.PositiveInfinitySymbol or NumberFormatInfo.NegativeInfinitySymbol instead of the expected number. If you require more precision, specify format with the "G17" format specification, which always returns 17 digits of precision, or "R", which returns 15 digits if the number can be represented with that precision or 17 digits if the number can only be represented with maximum precision.

The return value is formatted with NumberFormatInfo data for the current culture.

See also:
MSDN: formattingoverview | Double.Parse | String

Return to top


Overloaded Method: ToString(
   string format,
   IFormatProvider provider
)
Summary
Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.
C# Syntax:
public string ToString(
   string format,
   IFormatProvider provider
);
Parameters:

format

A format specification.

provider

An IFormatProvider that supplies culture-specific formatting information.

Return Value:
The string representation of the value of this instance as specified by format and provider.
Remarks
The return value can be NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' A lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of the return value are "100", "-123,456,789", "123.45+e6", "500", "3.1416", "600", "-0.123", and "-Infinity".

If format is null or an empty string, the return value for this instance is formatted with the general format specifier ("G").

By default, the return value only contains 15 digits of precision although a maximum of 17 digits is maintained internally. If the value of this instance has greater than 15 digits, ToString returns NumberFormatInfo.PositiveInfinitySymbol or NumberFormatInfo.NegativeInfinitySymbol instead of the expected number. If you require more precision, specify format with the "G17" format specification, which always returns 17 digits of precision, or "R", which returns 15 digits if the number can be represented with that precision or 17 digits if the number can only be represented with maximum precision.

The provider parameter is an IFormatProvider instance that obtains a NumberFormatInfo object that supplies culture-specific format information. If provider is null, the return value is formatted with NumberFormatInfo data for the current culture.

See also:
MSDN: formattingoverview | Double.Parse | String

Return to top


Method: TryParse(
   string s,
   NumberStyles style,
   IFormatProvider provider,
   out double result
)
Summary
Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.
C# Syntax:
public static bool TryParse(
   string s,
   NumberStyles style,
   IFormatProvider provider,
   out double result
);
Parameters:

s

A string containing a numberto convert.

style

The combination of one or more NumberStyles constants that indicate the permitted format of s.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

result

A double-precision floating-point number equivalent to the numeric value or symbol specified in s. If the return value is false, result is set to zero.

Return Value:
true if s is converted successfully; otherwise, false.
Remarks
The Double.TryParse method is like the Double.Parse method, except this method does not throw an exception if the conversion fails. If the conversion succeeds, the return value is true and the result parameter is set to the outcome of the conversion. If the conversion fails, the return value is false and the result parameter is set to zero.

The conversion fails if the s parameter is null or not a numeric value, the provider parameter does not yield a NumberFormatInfo object, or the style parameter is not a combination of bit flags from the NumberStyles enumeration.

The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

ws A series of white space characters. sign A negative sign or positive sign symbol. integral-digits A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits. '.' A culture-specific decimal point symbol. fractional-digits A series of digits specifying the fractional part of the number. 'e' An uppercase or lowercase character 'e', indicating exponential (scientific) notation. exponential-digits A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45+e6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

For more information about numeric formats, see the the conceptual topic at MSDN: formattingoverview topic.

See also:
MSDN: formattingoverview | Double.ToString

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.