System.Double Structure

public struct Double : IComparable, IFormattable, IComparable<Double>, IEquatable<Double>

Base Types

Object
  ValueType
    Double

This type implements IComparable, IFormattable, System.IComparable<System.Double>, and System.IEquatable<System.Double>.

Assembly

mscorlib

Library

ExtendedNumerics

Summary

Represents a 64-bit double-precision floating-point number.

Description

Double is a 64-bit double precision floating-point type that represents values ranging from approximately 5.0E-324 to 1.7E+308 and from approximately -5.0E-324 to -1.7E+308 with a precision of 15-16 decimal digits. The Double type conforms to standard IEC 60559:1989, Binary Floating-point Arithmetic for Microprocessor Systems.

A Double can represent the following values:

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:

Conforming implementations of the CLI are permitted to perform floating-point operations using a precision that is higher than that required by the Double type. For example, hardware architectures that support an "extended" or "long double" floating-point type with greater range and precision than the Double type could implicitly perform all floating-point operations using this higher precision type. Expressions evaluated using a higher precision might cause a finite result to be produced instead of an infinity.

See Also

System Namespace

Members

Double Methods

Double.CompareTo(double) Method
Double.CompareTo(System.Object) Method
Double.Equals(double) Method
Double.Equals(System.Object) Method
Double.GetHashCode Method
Double.IsInfinity Method
Double.IsNaN Method
Double.IsNegativeInfinity Method
Double.IsPositiveInfinity Method
Double.Parse(System.String) Method
Double.Parse(System.String, System.Globalization.NumberStyles) Method
Double.Parse(System.String, System.IFormatProvider) Method
Double.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
Double.ToString(System.String, System.IFormatProvider) Method
Double.ToString(System.IFormatProvider) Method
Double.ToString() Method
Double.ToString(System.String) Method

Double Fields

Double.Epsilon Field
Double.MaxValue Field
Double.MinValue Field
Double.NaN Field
Double.NegativeInfinity Field
Double.PositiveInfinity Field


Double.CompareTo(double) Method

public int CompareTo(double value);

Summary

Returns the sort order of the current instance compared to the specified Double .

Parameters

value
The Double to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueDescription
Any negative numberCurrent instance < value.

-or-

Current instance is a NaN and value is not a NaN.

Zero Current instance == value.

-or-

Current instance and value are both NaN, positive infinity, or negative infinity.

A positive numberCurrent instance > value.

-or-

Current instance is not a NaN and value is a NaN.

Description

[Note: This method is implemented to support the System.IComparable<Double> interface.]

See Also

System.Double Structure, System Namespace

Double.CompareTo(System.Object) Method

public int CompareTo(object value);

Summary

Returns the sort order of the current instance compared to the specified Object .

Parameters

value
The Object to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

ValueDescription
Any negative numberCurrent instance < value.

-or-

Current instance is a NaN and value is not a NaN and is not a null reference.

Zero Current instance == value.

-or-

Current instance and value are both NaN, positive infinity, or negative infinity.

A positive numberCurrent instance > value.

-or-

value is a null reference.

-or-

Current instance is not a NaN and value is a NaN.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is not a null reference and is not of type Double.

Description

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

]

See Also

System.Double Structure, System Namespace

Double.Equals(double) Method

public override bool Equals(double obj);

Summary

Determines whether the current instance and the specified Double represent the same value.

Parameters

obj
The Double to compare to the current instance.

Return Value

true if obj has the same value as the current instance, otherwise false . If either obj or the current instance is a NaN and the other is not, returns false . If obj and the current instance are both NaN, positive infinity, or negative infinity, returns true .

Description

[Note: This method is implemented to support the System.IEquatable<Double> interface.]

See Also

System.Double Structure, System Namespace

Double.Equals(System.Object) Method

public override bool Equals(object obj);

Summary

Determines whether the current instance and the specified Object represent the same type and value.

Parameters

obj
The Object to compare to the current instance.

Return Value

true if obj is a Double with the same value as the current instance, otherwise false . If obj is a null reference or is not an instance of Double, returns false . If either obj or the current instance is a NaN and the other is not, returns false . If obj and the current instance are both NaN, positive infinity, or negative infinity, returns true .

Description

[Note: This method overrides System.Object.Equals(System.Object).]

See Also

System.Double Structure, System Namespace

Double.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for this instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode. ]

See Also

System.Double Structure, System Namespace

Double.IsInfinity Method

public static bool IsInfinity(double d);

Summary

Determines whether the specified Double represents an infinity, which can be either positive or negative.

Parameters

d
The Double to be checked.

Return Value

true if d represents a positive or negative infinity value; otherwise false .

Description

[Note: Floating-point operations return positive or negative infinity values to signal an overflow condition. ]

See Also

System.Double Structure, System Namespace

Double.IsNaN Method

public static bool IsNaN(double d);

Summary

Determines whether the value of the specified Double is undefined (Not-a-Number).

Parameters

d
The Double to be checked.

Return Value

true if d represents a NaN value; otherwise false.

Description

[Note: Floating-point operations return NaN values to signal that the result of the operation is undefined. For example, dividing (Double) 0.0 by 0.0 results in a NaN value.]

See Also

System.Double Structure, System Namespace

Double.IsNegativeInfinity Method

public static bool IsNegativeInfinity(double d);

Summary

Determines whether the specified Double represents a negative infinity value.

Parameters

d
The Double to be checked.

Return Value

true if d represents a negative infinity value; otherwise false .

Description

[Note: Floating-point operations return negative infinity values to signal an overflow condition.]

See Also

System.Double Structure, System Namespace

Double.IsPositiveInfinity Method

public static bool IsPositiveInfinity(double d);

Summary

Determines whether the specified Double represents a positive infinity value.

Parameters

d
The Double to be checked.

Return Value

true if d represents a positive infinity value; otherwise false .

Description

[Note: Floating-point operations return positive infinity values to signal an overflow condition. ]

See Also

System.Double Structure, System Namespace

Double.Parse(System.String) Method

public static double Parse(string s);

Summary

Returns the specified String converted to a Double value.

Parameters

s
A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Float and/or System.Globalization.NumberStyles.AllowThousands style.

Return Value

The Double value obtained from s. If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a value that is less than System.Double.MinValue or greater than System.Double.MaxValue.

Description

This version of System.Double.Parse(System.String) is equivalent to System.Double.Parse(System.String) (s, System.Globalization.NumberStyles.Float| System.Globalization.NumberStyles.AllowThousands , null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo .]

See Also

System.Double Structure, System Namespace

Double.Parse(System.String, System.Globalization.NumberStyles) Method

public static double Parse(string s, NumberStyles style);

Summary

Returns the specified String converted to a Double value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style .
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Float and System.Globalization.NumberStyles.AllowThousands styles.

Return Value

The Double value obtained from s. If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a value that is less than System.Double.MinValue or greater than System.Double.MaxValue.

Description

This version of System.Double.Parse(System.String) is equivalent to System.Double.Parse(System.String) (s, style, null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo .]

See Also

System.Double Structure, System Namespace

Double.Parse(System.String, System.IFormatProvider) Method

public static double Parse(string s, IFormatProvider provider);

Summary

Returns the specified String converted to a Double value.

Parameters

s
A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Float and/or System.Globalization.NumberStyles.AllowThousands style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Double value obtained from s. If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a value that is less than System.Double.MinValue or greater than System.Double.MaxValue.

Description

This version of System.Double.Parse(System.String) is equivalent to System.Double.Parse(System.String)(s, System.Globalization.NumberStyles.Float| System.Globalization.NumberStyles.AllowThousands , provider).

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or a NumberFormatInfo cannot be obtained from provider , the formatting information for the current system culture is used.

See Also

System.Double Structure, System Namespace

Double.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method

public static double Parse(string s, NumberStyles style, IFormatProvider provider);

Summary

Returns the specified String converted to a Double value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style .
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Float and System.Globalization.NumberStyles.AllowThousands styles.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Double value obtained from s. If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference
FormatExceptions is not in the correct style.
OverflowExceptions represents a value that is less than System.Double.MinValue or greater than System.Double.MaxValue.

Description

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

See Also

System.Double Structure, System Namespace

Double.ToString(System.String, System.IFormatProvider) Method

public string ToString(string format, IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String containing a character that specifies the format of the returned string, optionally followed by a non-negative integer that specifies the precision of the number in the returned String .
provider
A IFormatProvider that supplies a NumberFormatInfo instance containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the information in the NumberFormatInfo instance supplied by provider.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

If provider is null or a NumberFormatInfo cannot be obtained from provider , the formatting information for the current system culture is used.

If format is a null reference, the general format specifier "G" is used.

The following table lists the format characters that are valid for the Double type.

Format CharactersDescription
"C", "c"Currency format.
"E", "e"Exponential notation format.
"F", "f"Fixed-point format.
"G", "g"General format.
"N", "n"Number format.
"P", "p"Percent format.
"R", "r"Round-trip format.
[Note: For a detailed description of formatting, see the IFormattable interface.

This method is implemented to support the IFormattable interface.

]

See Also

System.Double Structure, System Namespace

Double.ToString(System.IFormatProvider) Method

public string ToString(IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.

Description

This version of System.Double.ToString is equivalent to System.Double.ToString (null , provider ).

If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

[Note: The general format specifier formats the number in either fixed-point or exponential notation form. For a detailed description of the general format, see the IFormattable interface. ]

See Also

System.Double Structure, System Namespace

Double.ToString() Method

public override string ToString();

Summary

Returns a String representation of the value of the current instance.

Return Value

A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the current system culture.

Description

This version of System.Double.ToString is equivalent to System.Double.ToString (null , null ).

[Note: The general format specifier formats the number in either fixed-point or exponential notation form. For a detailed description of the general format, see the IFormattable interface.

This method overrides System.Object.ToString.

]

See Also

System.Double Structure, System Namespace

Double.ToString(System.String) Method

public string ToString(string format);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Double.ToString (String, IFormatProvider ).]

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

This version of System.Double.ToString is equivalent to System.Double.ToString (format, null ).

If format is a null reference, the general format specifier "G" is used.

Example

The following example shows the effects of various formats on the string returned by System.Double.ToString.

using System;
class test {
  public static void Main() {
    double d = 1234.56789;
    Console.WriteLine(d);
    string[] fmts = {"C","E","e5","F","G","N","P","R"};
    for (int i=0;i<fmts.Length;i++)
      Console.WriteLine("{0}: {1}", 
      fmts[i],d.ToString(fmts[i]));
  }
}
   
The output is

1234.56789

C: $1,234.57

E: 1.234568E+003

e5: 1.23457e+003

F: 1234.57

G: 1234.56789

N: 1,234.57

P: 123,456.79 %

R: 1234.56789

See Also

System.Double Structure, System Namespace

Double.Epsilon Field

public const double Epsilon = 4.9406564584124654e-324;

Summary

Represents the smallest positive Double value greater than zero.

Description

The value of this constant is 4.9406564584124654E-324.

See Also

System.Double Structure, System Namespace

Double.MaxValue Field

public const double MaxValue = 1.7976931348623157e+308;

Summary

Contains the maximum positive value for the Double type.

Description

The value of this constant is 1.7976931348623157E+308.

See Also

System.Double Structure, System Namespace

Double.MinValue Field

public const double MinValue = -1.7976931348623157e+308;

Summary

Contains the minimum (most negative) value for the Double type.

Description

The value of this constant is -1.7976931348623157E+308.

See Also

System.Double Structure, System Namespace

Double.NaN Field

public const double NaN = (double)0.0 / (double)0.0;

Summary

Represents an undefined result of operations involving Double .

Description

Not-a-Number (NaN) values are returned when the result of a Double operation is undefined.

A NaN value is not equal to any other value, including another NaN value.

The value of this field is obtained by dividing Double zero by zero.

[Note: System.Double.NaN represents one of many possible NaN values. To test whether a Double value is a NaN, use the System.Double.IsNaN(System.Double) method.]

See Also

System.Double Structure, System Namespace

Double.NegativeInfinity Field

public const double NegativeInfinity = (double)-1.0 / (double)(0.0);

Summary

Represents a negative infinity of type Double .

Description

The value of this constant is obtained by dividing a negative Double by zero.

[Note: To test whether a Double value is a negative infinity value, use the System.Double.IsNegativeInfinity(System.Double) method.]

See Also

System.Double Structure, System Namespace

Double.PositiveInfinity Field

public const double PositiveInfinity = (double)1.0 / (double)(0.0);

Summary

Represents a positive infinity of type Double .

Description

The value of this constant is obtained by dividing a positive Double by zero.

[Note: To test whether a Double value is a positive infinity value, use the System.Double.IsPositiveInfinity(System.Double) method.]

See Also

System.Double Structure, System Namespace