Java - Double class
Introduction
The Java Double class wraps a value of primitive type double in an object. An object of type Double contains a single field whose type is double.
Class Declaration
Following is the declaration for java.lang.Double class −
public final class Double
extends Number
implements Comparable<Double>
Field
Following are the fields for java.lang.Double class −
static int MAX_EXPONENT − This is the maximum exponent a finite double variable may have.
static double MAX_VALUE − This is the constant holding the largest positive finite value of type double, (2-2-52)×21023.
static int MIN_EXPONENT − This is the minimum exponent a normalized double variable may have.
static double MIN_NORMAL − This is the constant holding the smallest positive normal value of type double, 2-1022.
static double MIN_VALUE − This is the constant holding the smallest positive nonzero value of type double, 2-1074.
static double NaN − This is the constant holding a Not-a-Number (NaN) value of type double.
static double NEGATIVE_INFINITY − This is the constant holding the negative infinity of type double.
static double POSITIVE_INFINITY − This is the constant holding the positive infinity of type double.
static int SIZE − This is the number of bits used to represent a double value.
static Class<Double> TYPE − This is the class instance representing the primitive type double
Class constructors
| Sr.No. | Constructor & Description |
|---|---|
| 1 |
Double(double value) This constructs a newly allocated Double object that represents the primitive double argument. |
| 2 |
Double(String s) This constructs a newly allocated Double object that represents the floating-point value of type double represented by the string. |
Class methods
Methods inherited
This class inherits methods from the following classes −
- java.lang.Object
Example
The following example shows the usage of Double class to get double from a string. We've created a String and then using valueOf() method, we're retrieving getting a Double Object and then double object is printed.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
// create a String s and assign value to it
String s = "+120";
// create a Double object b
Double b;
// get the value of double from string
b = Double.valueOf(s);
// print b value
System.out.println( "Double value of string " + s + " is " + b );
}
}
Output
Let us compile and run the above program, this will produce the following result −
Double value of string +120 is 120.0