Most visited

Recently visited

Added in API level 1

Double

public final class Double
extends Number implements Comparable<Double>

java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Double


Double类将原始类型double的值包装在对象中。 类型为Double的对象包含类型为double的单个字段。

另外,该类提供了几种将 double转换为 StringString转换为 double ,以及处理 double时有用的其他常量和方法。

Summary

Constants

int BYTES

用于表示 double值的字节数。

int MAX_EXPONENT

变量可能具有的最大指数有限 double

double MAX_VALUE

的常量保持型的最大正的有限值 double ,(2-2 -52)A·2 1023。

int MIN_EXPONENT

一个归一化的 double变量可能有的最小指数。

double MIN_NORMAL

常数保持 double -1022的最小正常正常值。

double MIN_VALUE

的常量保持类型的最小正非零值 double ,2 -1074。

double NEGATIVE_INFINITY

持有类型为 double的负无穷大的 double

double NaN

一个常量,其中 double类型的非数字(NaN)值。

double POSITIVE_INFINITY

保持 double类型的正无穷大的 double

int SIZE

用于表示 double值的位数。

Fields

public static final Class<Double> TYPE

代表原始类型 doubleClass实例。

Public constructors

Double(double value)

构造一个新分配的 Double对象,该对象表示原始参数 double

Double(String s)

构造一个新分配的 Double对象,该对象表示由字符串表示的类型为 double的浮点值。

Public methods

byte byteValue()

将此 Double的值作为 byte (通过转换为 byte )。

static int compare(double d1, double d2)

比较两个指定的 double值。

int compareTo(Double anotherDouble)

以数字方式比较两个 Double对象。

static long doubleToLongBits(double value)

根据IEEE 754浮点“双格式”位布局返回指定浮点值的表示形式。

static long doubleToRawLongBits(double value)

根据IEEE 754浮点“双格式”位布局返回指定浮点值的表示形式,保留非数字(NaN)值。

double doubleValue()

返回此 Double对象的 double值。

boolean equals(Object obj)

将此对象与指定的对象进行比较。

float floatValue()

返回此 Double对象的 float值。

int hashCode()

返回此 Double对象的哈希码。

static int hashCode(double value)

返回double值的散列码; Double.hashCode()兼容。

int intValue()

返回此的值 Double作为 int (通过转换成键入 int )。

static boolean isFinite(double d)

如果参数是有限浮点值,则返回true ; 否则返回false (对于NaN和无穷大参数)。

boolean isInfinite()

返回 true如果此 Double值是无限大, false否则。

static boolean isInfinite(double v)

返回 true如果指定的数是无限大, false否则。

static boolean isNaN(double v)

返回 true如果指定的号码是一个不一个数字(NaN)值, false否则。

boolean isNaN()

返回 true如果此 Double值是不是非数字(NAN), false否则。

static double longBitsToDouble(long bits)

返回对应于给定位表示的 double值。

long longValue()

返回此的值 Double作为 long (通过转换成键入 long )。

static double max(double a, double b)

通过调用 Math.max返回两个 double值中的较大者。

static double min(double a, double b)

通过调用 Math.min返回两个 double值中较小的 Math.min

static double parseDouble(String s)

返回一个新的 double初始化为由指定的 String表示的值,如 valueOf类的 valueOf方法执行的 Double

short shortValue()

将此 Double的值作为 short (通过转换为 short )。

static double sum(double a, double b)

根据+运算符将两个 double值相加。

static String toHexString(double d)

返回 double参数的十六进制字符串表示形式。

static String toString(double d)

返回 double参数的字符串表示形式。

String toString()

返回此 Double对象的字符串表示形式。

static Double valueOf(String s)

返回保存由参数字符串 s表示的 double值的 Double对象。

static Double valueOf(double d)

返回表示指定的 double值的 Double实例。

Inherited methods

From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

BYTES

Added in API level 24
int BYTES

用于表示 double值的字节数。

常量值:8(0x00000008)

MAX_EXPONENT

Added in API level 9
int MAX_EXPONENT

变量可能有的最大指数是有限的double 它等于由Math.getExponent(Double.MAX_VALUE)返回的值。

常量值:1023(0x000003ff)

MAX_VALUE

Added in API level 1
double MAX_VALUE

的常量保持型的最大正的有限值double ,(2-2 -52)A·2 1023。 它等于十六进制浮点0x1.fffffffffffffP+1023 ,也等于Double.longBitsToDouble(0x7fefffffffffffffL)

常数值:1.7976931348623157E308

MIN_EXPONENT

Added in API level 9
int MIN_EXPONENT

归一化的double变量可能具有的最小指数。 它等于Math.getExponent(Double.MIN_NORMAL)返回的值。

常量值:-1022(0xfffffc02)

MIN_NORMAL

Added in API level 9
double MIN_NORMAL

一个常量保持double -1022型的最小正常正常值。 它等于十六进制浮点0x1.0p-1022 ,也等于Double.longBitsToDouble(0x0010000000000000L)

常数值:2.2250738585072014E-308

MIN_VALUE

Added in API level 1
double MIN_VALUE

的常量保持类型的最小正非零值double ,2 -1074。 它等于十六进制浮点0x0.0000000000001P-1022 ,也等于Double.longBitsToDouble(0x1L)

常数值:4.9E-324

NEGATIVE_INFINITY

Added in API level 1
double NEGATIVE_INFINITY

类型为double的负无穷大的double 它等于Double.longBitsToDouble(0xfff0000000000000L)返回的值。

常数值:-Infinity

NaN

Added in API level 1
double NaN

一个常量包含类型为double非数字(NaN)值。 它相当于Double.longBitsToDouble(0x7ff8000000000000L)返回的值。

常数值:NaN

POSITIVE_INFINITY

Added in API level 1
double POSITIVE_INFINITY

保持double类型的正无穷大的double 它等于Double.longBitsToDouble(0x7ff0000000000000L)返回的值。

恒定值:无限

SIZE

Added in API level 1
int SIZE

用于表示 double值的位数。

常量值:64(0x00000040)

Fields

TYPE

Added in API level 1
Class<Double> TYPE

表示原始类型 doubleClass实例。

Public constructors

Double

Added in API level 1
Double (double value)

构造一个新分配 Double对象表示基本 double说法。

Parameters
value double: the value to be represented by the Double.

Double

Added in API level 1
Double (String s)

构造一个新分配的Double对象,该对象表示由字符串表示的类型为double的浮点值。 字符串被转换为double值,就像通过valueOf方法一样。

Parameters
s String: a string to be converted to a Double.
Throws
NumberFormatException if the string does not contain a parsable number.

也可以看看:

Public methods

byteValue

Added in API level 1
byte byteValue ()

将此 Double的值作为 byte (通过转换为 byte )。

Returns
byte the double value represented by this object converted to type byte

compare

Added in API level 1
int compare (double d1, 
                double d2)

比较两个指定的double值。 返回的整数值的符号与调用返回的整数的符号相同:

    new Double(d1).compareTo(new Double(d2))
 

Parameters
d1 double: the first double to compare
d2 double: the second double to compare
Returns
int the value 0 if d1 is numerically equal to d2; a value less than 0 if d1 is numerically less than d2; and a value greater than 0 if d1 is numerically greater than d2.

compareTo

Added in API level 1
int compareTo (Double anotherDouble)

以数字方式比较两个Double对象。 有两种方法可以使用此方法执行的比较与Java语言数值比较运算符( <, <=, ==, >=, > )在应用于基本double值时执行的比较有所不同:

  • Double.NaN is considered by this method to be equal to itself and greater than all other double values (including Double.POSITIVE_INFINITY).
  • 0.0d is considered by this method to be greater than -0.0d.
This ensures that the natural ordering of Double objects imposed by this method is consistent with equals.

Parameters
anotherDouble Double: the Double to be compared.
Returns
int the value 0 if anotherDouble is numerically equal to this Double; a value less than 0 if this Double is numerically less than anotherDouble; and a value greater than 0 if this Double is numerically greater than anotherDouble.

doubleToLongBits

Added in API level 1
long doubleToLongBits (double value)

根据IEEE 754浮点“双格式”位布局返回指定浮点值的表示形式。

位63(由掩码0x8000000000000000L选择的位)表示浮点数的符号。 位62-52(由掩码0x7ff0000000000000L选择的位)表示指数。 位51-0(由掩码0x000fffffffffffffL选择的位)表示0x000fffffffffffffL的有效位(有时称为尾数)。

如果参数是正无穷大,结果是 0x7ff0000000000000L

如果参数是负无穷大,则结果为 0xfff0000000000000L

如果参数是NaN,那么结果是 0x7ff8000000000000L

在所有情况下,结果都是一个 long整数,当给予 longBitsToDouble(long)方法时,将产生一个与 doubleToLongBits的参数相同的浮点值(除了所有NaN值都折叠为单个“规范”NaN值)。

Parameters
value double: a double precision floating-point number.
Returns
long the bits that represent the floating-point number.

doubleToRawLongBits

Added in API level 1
long doubleToRawLongBits (double value)

根据IEEE 754浮点“双格式”位布局返回指定浮点值的表示形式,保留非数字(NaN)值。

位63(由掩码0x8000000000000000L选择的位)表示浮点数的符号。 位62-52(由掩码0x7ff0000000000000L选择的位)表示指数。 位51-0(由掩码0x000fffffffffffffL选择的位)表示0x000fffffffffffffL的有效位(有时称为尾数)。

如果参数是正无穷大,结果是 0x7ff0000000000000L

如果参数是负无穷大,结果是 0xfff0000000000000L

如果参数是NaN,则结果是代表实际NaN值的long整数。 doubleToLongBits方法不同, doubleToRawLongBits不会将编码NaN的所有位模式折叠为单个“规范”NaN值。

在所有情况下,结果都是一个 long整数,当给予 longBitsToDouble(long)方法时,将产生一个与 doubleToRawLongBits的参数相同的浮点值。

Parameters
value double: a double precision floating-point number.
Returns
long the bits that represent the floating-point number.

doubleValue

Added in API level 1
double doubleValue ()

返回此 Double对象的 double值。

Returns
double the double value represented by this object

equals

Added in API level 1
boolean equals (Object obj)

将此对象与指定的对象进行比较。 其结果是true当且仅当该参数不是null并且是Double对象,它表示一个double具有相同的值作为double该对象表示。 为此,当且仅当方法doubleToLongBits(double)在应用于每个值时返回相同的long值时,两个doubledouble视为相同。

请注意,在大多数情况下,类的两个实例 Doubled1d2 ,价值 d1.equals(d2)true当且仅当

d1.doubleValue() == d2.doubleValue()

也有值true 但是,有两个例外:

  • If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false.
  • If d1 represents +0.0 while d2 represents -0.0, or vice versa, the equal test has the value false, even though +0.0==-0.0 has the value true.
This definition allows hash tables to operate properly.

Parameters
obj Object: the object to compare with.
Returns
boolean true if the objects are the same; false otherwise.

也可以看看:

floatValue

Added in API level 1
float floatValue ()

返回此 Double对象的 float值。

Returns
float the double value represented by this object converted to type float

hashCode

Added in API level 1
int hashCode ()

返回此Double对象的哈希码。 结果是long整数位表示的两个半部分(与由方法doubleToLongBits(double)产生的完全相同)由此Double对象表示的基本double值的两半的异或结果。 也就是说,哈希码是表达式的值:

(int)(v^(v>>>32))
where v is defined by:
long v = Double.doubleToLongBits(this.doubleValue());

Returns
int a hash code value for this object.

hashCode

Added in API level 24
int hashCode (double value)

返回double值的哈希码; Double.hashCode()兼容。

Parameters
value double: the value to hash
Returns
int a hash code value for a double value.

intValue

Added in API level 1
int intValue ()

返回此的值 Double作为 int (通过转换成键入 int )。

Returns
int the double value represented by this object converted to type int

isFinite

Added in API level 24
boolean isFinite (double d)

如果参数是有限浮点值,则返回true ; 否则返回false (对于NaN和无穷大参数)。

Parameters
d double: the double value to be tested
Returns
boolean true if the argument is a finite floating-point value, false otherwise.

isInfinite

Added in API level 1
boolean isInfinite ()

返回 true如果此 Double值是无限大, false否则。

Returns
boolean true if the value represented by this object is positive infinity or negative infinity; false otherwise.

isInfinite

Added in API level 1
boolean isInfinite (double v)

返回 true如果指定的数是无限大, false否则。

Parameters
v double: the value to be tested.
Returns
boolean true if the value of the argument is positive infinity or negative infinity; false otherwise.

isNaN

Added in API level 1
boolean isNaN (double v)

返回 true如果指定的号码是一个不一个数字(NaN)值, false否则。

Parameters
v double: the value to be tested.
Returns
boolean true if the value of the argument is NaN; false otherwise.

isNaN

Added in API level 1
boolean isNaN ()

返回 true如果此 Double值是不是非数字(NAN), false否则。

Returns
boolean true if the value represented by this object is NaN; false otherwise.

longBitsToDouble

Added in API level 1
double longBitsToDouble (long bits)

返回对应于给定位表示的double值。 该参数被认为是根据IEEE 754浮点“双格式”位布局的浮点值的表示。

如果参数是 0x7ff0000000000000L ,结果是正无穷。

如果参数是 0xfff0000000000000L ,结果是负无穷大。

如果参数在上述范围内的任何值0x7ff0000000000001L通过0x7fffffffffffffffL或在范围0xfff0000000000001L通过0xffffffffffffffffL ,结果是NaN。 Java提供的IEEE 754浮点操作不能区分具有不同位模式的相同类型的两个NaN值。 NaN的不同值只能通过使用Double.doubleToRawLongBits方法区分。

在所有其他情况下,让 sem为可以从参数计算的三个值:

 int s = ((bits >> 63) == 0) ? 1 : -1;
 int e = (int)((bits >> 52) & 0x7ffL);
 long m = (e == 0) ?
                 (bits & 0xfffffffffffffL) << 1 :
                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 
Then the floating-point result equals the value of the mathematical expression s· m·2 e-1075.

请注意,此方法可能无法返回与long参数完全相同的位模式的double NaN。 IEEE 754区分了两种NaN,安静的NaN和信令NaN 这两种NaN之间的差异在Java中通常不可见。 信令NaN上的算术运算将它们变成了安静的NaN,它们具有不同但通常相似的位模式。 然而,在一些处理器上,仅仅复制一个信令NaN也会执行该转换。 特别是,复制信号NaN以将其返回给调用方法可执行此转换。 因此longBitsToDouble可能无法以信号NaN位模式返回double 因此,对于某些long值, doubleToRawLongBits(longBitsToDouble(start))可能等于start 此外,哪些特定的位模式表示信令NaN是平台相关的; 尽管所有NaN位模式(无声或信令)必须处于上述NaN范围内。

Parameters
bits long: any long integer.
Returns
double the double floating-point value with the same bit pattern.

longValue

Added in API level 1
long longValue ()

返回此的值 Double作为 long (通过转换成键入 long )。

Returns
long the double value represented by this object converted to type long

max

Added in API level 24
double max (double a, 
                double b)

通过调用 Math.max返回两个 double值中较大的 Math.max

Parameters
a double: the first operand
b double: the second operand
Returns
double the greater of a and b

也可以看看:

min

Added in API level 24
double min (double a, 
                double b)

通过调用 Math.min返回两个 double值中较小的 Math.min

Parameters
a double: the first operand
b double: the second operand
Returns
double the smaller of a and b.

也可以看看:

parseDouble

Added in API level 1
double parseDouble (String s)

返回一个新 double初始化为指定的代表的值 String ,如通过执行 valueOf类的方法 Double

Parameters
s String: the string to be parsed.
Returns
double the double value represented by the string argument.
Throws
NullPointerException if the string is null
NumberFormatException if the string does not contain a parsable double.

也可以看看:

shortValue

Added in API level 1
short shortValue ()

返回此的值 Double作为 short (通过强制转换为 short )。

Returns
short the double value represented by this object converted to type short

sum

Added in API level 24
double sum (double a, 
                double b)

根据+运算符将两个 double值相加。

Parameters
a double: the first operand
b double: the second operand
Returns
double the sum of a and b

也可以看看:

toHexString

Added in API level 1
String toHexString (double d)

返回double参数的十六进制字符串表示形式。 下面提到的所有字符都是ASCII字符。

  • If the argument is NaN, the result is the string "NaN".
  • Otherwise, the result is a string that represents the sign and magnitude of the argument. If the sign is negative, the first character of the result is '-' ('\u002D'); if the sign is positive, no sign character appears in the result. As for the magnitude m:
    • If m is infinity, it is represented by the string "Infinity"; thus, positive infinity produces the result "Infinity" and negative infinity produces the result "-Infinity".
    • If m is zero, it is represented by the string "0x0.0p0"; thus, negative zero produces the result "-0x0.0p0" and positive zero produces the result "0x0.0p0".
    • If m is a double value with a normalized representation, substrings are used to represent the significand and exponent fields. The significand is represented by the characters "0x1." followed by a lowercase hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed unless all the digits are zero, in which case a single zero is used. Next, the exponent is represented by "p" followed by a decimal string of the unbiased exponent as if produced by a call to Integer.toString on the exponent value.
    • If m is a double value with a subnormal representation, the significand is represented by the characters "0x0." followed by a hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed. Next, the exponent is represented by "p-1022". Note that there must be at least one nonzero digit in a subnormal significand.

Examples

Floating-point Value Hexadecimal String
1.0 0x1.0p0
-1.0 -0x1.0p0
2.0 0x1.0p1
3.0 0x1.8p1
0.5 0x1.0p-1
0.25 0x1.0p-2
Double.MAX_VALUE 0x1.fffffffffffffp1023
Minimum Normal Value 0x1.0p-1022
Maximum Subnormal Value 0x0.fffffffffffffp-1022
Double.MIN_VALUE 0x0.0000000000001p-1022

Parameters
d double: the double to be converted.
Returns
String a hex string representation of the argument.

toString

Added in API level 1
String toString (double d)

返回double参数的字符串表示形式。 下面提到的所有字符都是ASCII字符。

  • If the argument is NaN, the result is the string "NaN".
  • Otherwise, the result is a string that represents the sign and magnitude (absolute value) of the argument. If the sign is negative, the first character of the result is '-' ('\u002D'); if the sign is positive, no sign character appears in the result. As for the magnitude m:
    • If m is infinity, it is represented by the characters "Infinity"; thus, positive infinity produces the result "Infinity" and negative infinity produces the result "-Infinity".
    • If m is zero, it is represented by the characters "0.0"; thus, negative zero produces the result "-0.0" and positive zero produces the result "0.0".
    • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('\u002E'), followed by one or more decimal digits representing the fractional part of m.
    • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." Let n be the unique integer such that 10nm < 10n+1; then let a be the mathematically exact quotient of m and 10n so that 1 ≤ a < 10. The magnitude is then represented as the integer part of a, as a single decimal digit, followed by '.' ('\u002E'), followed by decimal digits representing the fractional part of a, followed by the letter 'E' ('\u0045'), followed by a representation of n as a decimal integer, as produced by the method toString(int).
How many digits must be printed for the fractional part of m or a? There must be at least one digit to represent the fractional part, and beyond that as many, but only as many, more digits as are needed to uniquely distinguish the argument value from adjacent values of type double. That is, suppose that x is the exact mathematical value represented by the decimal representation produced by this method for a finite nonzero argument d. Then d must be the double value nearest to x; or if two double values are equally close to x, then d must be one of them and the least significant bit of the significand of d must be 0.

要创建浮点值的本地化字符串表示,请使用 NumberFormat子类。

Parameters
d double: the double to be converted.
Returns
String a string representation of the argument.

toString

Added in API level 1
String toString ()

返回此Double对象的字符串表示形式。 此对象表示的原语double值完全转换为字符串,就像通过一个参数的方法toString

Returns
String a String representation of this object.

也可以看看:

valueOf

Added in API level 1
Double valueOf (String s)

返回保存由参数字符串 s表示的 double值的 Double对象。

如果 snull ,则引发 NullPointerException

忽略s中的前导和尾随空白字符。 删除空白就好像通过trim()方法一样; 也就是说,ASCII空间和控制字符都被删除。 s的其余部分应构成一个FloatValue ,如词法语法规则所述:

FloatValue:
Signopt NaN
Signopt Infinity
Signopt FloatingPointLiteral
Signopt HexFloatingPointLiteral
SignedInteger

HexFloatingPointLiteral:
HexSignificand BinaryExponent FloatTypeSuffixopt

HexSignificand:
HexNumeral
HexNumeral .
0x HexDigitsopt . HexDigits
0X HexDigitsopt . HexDigits

BinaryExponent:
BinaryExponentIndicator SignedInteger

BinaryExponentIndicator:
p
P
where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java™ Language Specification, except that underscores are not accepted between digits. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value. Note that the round-to-nearest rule also implies overflow and underflow behaviour; if the exact value of s is large enough in magnitude (greater than or equal to ( MAX_VALUE + ulp(MAX_VALUE)/2), rounding to double will result in an infinity and if the exact value of s is small enough in magnitude (less than or equal to MIN_VALUE/2), rounding to float will result in a zero. Finally, after rounding a Double object representing this double value is returned.

要解释浮点值的本地化字符串表示,请使用 NumberFormat子类。

请注意,尾部格式说明符,确定浮点文字类型的说明符( 1.0ffloat值; 1.0ddouble值), 不会影响此方法的结果。 换句话说,输入字符串的数值直接转换为目标浮点类型。 两步转换序列(字符串为float后跟floatdouble等同于将字符串直接转换为double 例如, float文字0.1f等于double0.10000000149011612 ; 所述float字面0.1f表示不同的数值比double字面0.1 (数值0.1不能用二进制浮点数精确表示。)

为避免在无效字符串上调用此方法并引发 NumberFormatException ,可使用下面的正则表达式来筛选输入字符串:


  final String Digits     = "(\\p{Digit}+)";
  final String HexDigits  = "(\\p{XDigit}+)";
  // an exponent is 'e' or 'E' followed by an optionally
  // signed decimal integer.
  final String Exp        = "[eE][+-]?"+Digits;
  final String fpRegex    =
      ("[\\x00-\\x20]*"+  // Optional leading "whitespace"
       "[+-]?(" + // Optional sign character
       "NaN|" +           // "NaN" string
       "Infinity|" +      // "Infinity" string

       // A decimal floating-point string representing a finite positive
       // number without a leading sign has at most five basic pieces:
       // Digits . Digits ExponentPart FloatTypeSuffix
       //
       // Since this method allows integer-only strings as input
       // in addition to strings of floating-point literals, the
       // two sub-patterns below are simplifications of the grammar
       // productions from section 3.10.2 of
       // The Java™ Language Specification.

       // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
       "((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+

       // . Digits ExponentPart_opt FloatTypeSuffix_opt
       "(\\.("+Digits+")("+Exp+")?)|"+

       // Hexadecimal strings
       "((" +
        // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
        "(0[xX]" + HexDigits + "(\\.)?)|" +

        // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
        "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +

        ")[pP][+-]?" + Digits + "))" +
       "[fFdD]?))" +
       "[\\x00-\\x20]*");// Optional trailing "whitespace"

  if (Pattern.matches(fpRegex, myString))
      Double.valueOf(myString); // Will not throw NumberFormatException
  else {
      // Perform suitable alternative action
  }
 

Parameters
s String: the string to be parsed.
Returns
Double a Double object holding the value represented by the String argument.
Throws
NumberFormatException if the string does not contain a parsable number.

valueOf

Added in API level 1
Double valueOf (double d)

返回表示指定的double值的Double实例。 如果不需要新的Double实例,则通常应该优先使用此方法,而不是构造函数Double(double) ,因为此方法可能通过缓存经常请求的值来产生显着更好的空间和时间性能。

Parameters
d double: a double value.
Returns
Double a Double instance representing d.

Hooray!