[Serializable] |
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:
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. |
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. |
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:
public const double Epsilon;
|
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.
public const double MaxValue;
|
public const double MinValue;
|
public const double NaN;
|
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.
public const double NegativeInfinity;
|
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.
public const double PositiveInfinity;
|
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.
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. |
Exception Type | Condition |
---|---|
ArgumentException | value is not a Double or 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.
obj
~Double(); |
public override int GetHashCode(); |
public Type GetType(); |
public TypeCode GetTypeCode(); |
d
d
d
d
protected object MemberwiseClone(); |
s
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. |
[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.
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.
public static double Parse( |
s
provider
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. |
[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.
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.
public static double Parse( |
s
style
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. |
[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.
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.
public static double Parse( |
s
style
provider
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. |
[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.
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.
public override string ToString(); |
[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.
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.
public string ToString( |
provider
[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.
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.
format
Exception Type | Condition |
---|---|
FormatException | format is invalid. |
[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.
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.
public string ToString( |
format
provider
[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.
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.
public static bool TryParse( |
s
style
provider
result
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.
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.