public struct Double : IComparable, IFormattable
Object
ValueType
DoubleThis type implements IComparable and IFormattable.
mscorlib
ExtendedNumerics
Represents a 64-bit double-precision floating-point number.
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 finite set of non-zero values of the form s * m * 2e, where s is 1 or -1, and 0 < m < 253 and -1075 <= e <= 970.
- Positive infinity and negative infinity. Infinities are produced by operations that produce results with a magnitude greater than that which can be represented by a Double, such as dividing a non-zero number by zero. For example, using Double operands
, 1.0 / 0.0
yields positive infinity, and-1.0 / 0.0
yields negative infinity. Operations include passing parameters and returning values.- The Not-a-Number value (NaN). NaN values are produced by invalid floating-point operations, such as dividing zero by zero.
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 may cause a finite result to be produced instead of an infinity.
- If the result of a floating-point operation is too small for the destination format, the result of the operation is zero.
- If the magnitude of the result of a floating-point operation is too large for the destination format, the result of the operation is positive infinity or negative infinity, as appropriate for the sign of the result.
- If a floating-point operation is invalid, the result of the operation is NaN.
- If one or both operands of a floating-point operation are NaN, the result of the operation is NaN.
System Namespace
Double Methods
Double.CompareTo Method
Double.Equals 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.IFormatProvider) Method
Double.ToString(System.String, 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
public int CompareTo(object value);
Returns the sort order of the current instance compared to the specified Object .
- value
- The Object to compare to the current instance.
A Int32 containing a value that reflects the sort order of the current instance as compared to value. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number.
Value Description Any negative number Current instance < value. Current instance is a NaN and value is not a NaN and is not a null reference.
Zero Current instance == value. Current instance and value are both NaN, positive infinity, or negative infinity.
Any positive number Current instance > value. value is a null reference.
Current instance is not a NaN and value is a NaN.
Exception Type Condition ArgumentException value is not a null reference and is not of type Double.
[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.]
System.Double Structure, System Namespace
public override bool Equals(object obj);
Determines whether the current instance and the specified Object represent the same type and value.
- obj
- The Object to compare to the current instance.
true
if obj is a Double with the same value as the current instance, otherwisefalse
. If obj is a null reference or is not an instance of Double, returnsfalse
. If either obj or the current instance is a NaN and the other is not, returnsfalse
. If obj and the current instance are both NaN, positive infinity, or negative infinity, returnstrue
.
[Note: This method overrides System.Object.Equals(System.Object).]
System.Double Structure, System Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for this instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode. ]
System.Double Structure, System Namespace
public static bool IsInfinity(double d);
Determines whether the specified Double represents an infinity, which can be either positive or negative.
- d
- The Double to be checked.
true
if d represents a positive or negative infinity value; otherwisefalse
.
[Note: Floating-point operations return positive or negative infinity values to signal an overflow condition. ]
System.Double Structure, System Namespace
public static bool IsNaN(double d);
Determines whether the value of the specified Double is undefined (Not-a-Number).
- d
- The Double to be checked.
true
if d represents a NaN value; otherwisefalse.
[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.]
System.Double Structure, System Namespace
public static bool IsNegativeInfinity(double d);
Determines whether the specified Double represents a negative infinity value.
- d
- The Double to be checked.
true
if d represents a negative infinity value; otherwisefalse
.
[Note: Floating-point operations return negative infinity values to signal an overflow condition.]
System.Double Structure, System Namespace
public static bool IsPositiveInfinity(double d);
Determines whether the specified Double represents a positive infinity value.
- d
- The Double to be checked.
true
if d represents a positive infinity value; otherwisefalse
.
[Note: Floating-point operations return positive infinity values to signal an overflow condition. ]
System.Double Structure, System Namespace
public static double Parse(string s);
Returns the specified String converted to a Double value.
- 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.
The Double value obtained from s. If the parsed value is less than System.Double.MinValue, this method returns System.Double.NegativeInfinity . If the parsed value is greater than System.Double.MaxValue, this method returns System.Double.PositiveInfinity . If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style.
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 .]
System.Double Structure, System Namespace
public static double Parse(string s, NumberStyles style);
Returns the specified String converted to a Double value.
- 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.
The Double value obtained from s. If the parsed value is less than System.Double.MinValue, this method returns System.Double.NegativeInfinity . If the parsed value is greater than System.Double.MaxValue, this method returns System.Double.PositiveInfinity . If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style.
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 .]
System.Double Structure, System Namespace
public static double Parse(string s, IFormatProvider provider);
Returns the specified String converted to a Double value.
- 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.
The Double value obtained from s. If the parsed value is less than System.Double.MinValue, this method returns System.Double.NegativeInfinity . If the parsed value is greater than System.Double.MaxValue, this method returns System.Double.PositiveInfinity . If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct style.
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.
System.Double Structure, System Namespace
public static double Parse(string s, NumberStyles style, IFormatProvider provider);
Returns the specified String converted to a Double value.
- 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.
The Double value obtained from s. If the parsed value is less than System.Double.MinValue, this method returns System.Double.NegativeInfinity . If the parsed value is greater than System.Double.MaxValue, this method returns System.Double.PositiveInfinity . If s equals System.Globalization.NumberFormatInfo.NaNSymbol, this method returns System.Double.NaN .
Exception Type Condition ArgumentNullException s is a null reference FormatException s is not in the correct style.
The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider isnull
or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.
System.Double Structure, System Namespace
public string ToString(IFormatProvider provider);
Returns a String representation of the value of the current instance.
- provider
- A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.
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.
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. ]
System.Double Structure, System Namespace
public string ToString(string format, IFormatProvider provider);
Returns a String representation of the value of the current instance.
- 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.
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.
Exception Type Condition FormatException format is invalid.
If provider isnull
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.
[Note: For a detailed description of formatting, see the IFormattable interface.
Format Characters Description "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. This method is implemented to support the IFormattable interface.
]
System.Double Structure, System Namespace
public override string ToString();
Returns a String representation of the value of the current instance.
A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the current system culture.
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.
]
System.Double Structure, System Namespace
public string ToString(string format);
Returns a String representation of the value of the current instance.
- format
- A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Double.ToString (String, IFormatProvider ).]
A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.
Exception Type Condition FormatException format is invalid.
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.
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
System.Double Structure, System Namespace
public const double Epsilon = 4.9406564584124654e-324;
Represents the smallest positive Double value greater than zero.
The value of this constant is 4.9406564584124654E-324.
System.Double Structure, System Namespace
public const double MaxValue = 1.7976931348623157e+308;
Contains the maximum positive value for the Double type.
The value of this constant is 1.7976931348623157E+308.
System.Double Structure, System Namespace
public const double MinValue = -1.7976931348623157e+308;
Contains the minimum (most negative) value for the Double type.
The value of this constant is -1.7976931348623157E+308.
System.Double Structure, System Namespace
public const double NaN = (double)0.0 / (double)0.0;
Represents an undefined result of operations involving Double .
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.]
System.Double Structure, System Namespace
public const double NegativeInfinity = (double)-1.0 / (double)(0.0);
Represents a negative infinity of type Double .
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.]
System.Double Structure, System Namespace
public const double PositiveInfinity = (double)1.0 / (double)(0.0);
Represents a positive infinity of type Double .
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.]
System.Double Structure, System Namespace