Java by API/java.lang/Double

Материал из Java эксперт
Перейти к: навигация, поиск

Double: byteValue()

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   Double dObj = new Double("10.50");
   byte b = dObj.byteValue();
   System.out.println(b);
   short s = dObj.shortValue();
   System.out.println(s);
   int i = dObj.intValue();
   System.out.println(i);
   float f = dObj.floatValue();
   System.out.println(f);
   double d = dObj.doubleValue();
   System.out.println(d);
 }

} /* 10 10 10 10.5 10.5

  • /


 </source>
   
  
 
  



Double: compare(double d1, double d2)

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   double d1 = 5.5;
   double d2 = 5.4;
   int i1 = Double.rupare(d1, d2);
   if (i1 > 0) {
     System.out.println(">");
   } else if (i1 < 0) {
     System.out.println("<");
   } else {
     System.out.println("=");
   }
   Double dObj1 = new Double("5.5");
   Double dObj2 = new Double("5.4");
   int i2 = dObj1.rupareTo(dObj2);
   if (i2 > 0) {
     System.out.println(">");
   } else if (i2 < 0) {
     System.out.println("<");
   } else {
     System.out.println("=");
   }
 }

}


 </source>
   
  
 
  



Double: compareTo(Double anotherDouble)

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   double d1 = 5.5;
   double d2 = 5.4;
   int i1 = Double.rupare(d1, d2);
   if (i1 > 0) {
     System.out.println(">");
   } else if (i1 < 0) {
     System.out.println("<");
   } else {
     System.out.println("=");
   }
   Double dObj1 = new Double("5.5");
   Double dObj2 = new Double("5.4");
   int i2 = dObj1.rupareTo(dObj2);
   if (i2 > 0) {
     System.out.println(">");
   } else if (i2 < 0) {
     System.out.println("<");
   } else {
     System.out.println("=");
   }
 }

}


 </source>
   
  
 
  



Double: doubleValue()

   <source lang="java">
 

/*

* Output:

10.234

*/

public class MainClass {

 public static void main(String args[]) {
   double degrees = Double.valueOf("10.234").doubleValue();
   System.out.println(degrees);
 }

}


 </source>
   
  
 
  



Double: equals

   <source lang="java">
 

/*

* Output:

3.14159 = 3.14159 -> true

* 
 
*/

public class MainClass {

 public static void main(String args[]) {
 Double d1 = new Double(3.14159);
 Double d2 = new Double("314159E-5");
 System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
 }

}



 </source>
   
  
 
  



Double: floatValue()

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   Double dObj = new Double("10.50");
   byte b = dObj.byteValue();
   System.out.println(b);
   short s = dObj.shortValue();
   System.out.println(s);
   int i = dObj.intValue();
   System.out.println(i);
   float f = dObj.floatValue();
   System.out.println(f);
   double d = dObj.doubleValue();
   System.out.println(d);
 }

} /* 10 10 10 10.5 10.5

  • /


 </source>
   
  
 
  



Double: intValue()

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   Double dObj = new Double("10.50");
   byte b = dObj.byteValue();
   System.out.println(b);
   short s = dObj.shortValue();
   System.out.println(s);
   int i = dObj.intValue();
   System.out.println(i);
   float f = dObj.floatValue();
   System.out.println(f);
   double d = dObj.doubleValue();
   System.out.println(d);
 }

} /* 10 10 10 10.5 10.5

  • /


 </source>
   
  
 
  



Double: isInfinite()

   <source lang="java">
 

/*

* Output:
* 

Infinity: true, false NaN: false, true

*  
*/

public class MainClass {

 public static void main(String args[]) {
 Double d1 = new Double(1/0.);
 Double d2 = new Double(0/0.);
 System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
 System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
 }

}



 </source>
   
  
 
  



Double: isNaN()

   <source lang="java">
 

/*

* Output:
* 

Infinity: true, false NaN: false, true

*  
*/

public class MainClass {

 public static void main(String args[]) {
 Double d1 = new Double(1/0.);
 Double d2 = new Double(0/0.);
 System.out.println(d1 + ": " + d1.isInfinite() + ", " + d1.isNaN());
 System.out.println(d2 + ": " + d2.isInfinite() + ", " + d2.isNaN());
 }

}



 </source>
   
  
 
  



Double.MAX_VALUE

   <source lang="java">
 

/*

* Output:

1.7976931348623157E308

*/

public class MainClass {

 public static void main(String args[]) {
   System.out.println(Double.MAX_VALUE);
 }

}


 </source>
   
  
 
  



Double.MIN_VALUE

   <source lang="java">
 

/*

* Output:

4.9E-324

*/

public class MainClass {

 public static void main(String args[]) {
   System.out.println(Double.MIN_VALUE);
 }

}


 </source>
   
  
 
  



Double.NEGATIVE_INFINITY

   <source lang="java">
 

/*

* Output:

-Infinity

*/

public class MainClass {

 public static void main(String args[]) {
   System.out.println(Double.NEGATIVE_INFINITY);
 }

}


 </source>
   
  
 
  



Double: parseDouble(String s)

   <source lang="java">
 

public class Main {

 public static void main(String[] argv) throws Exception {
   double d = Double.parseDouble("123.4e10");
   System.out.println(d);
 }

}


 </source>
   
  
 
  



Double.POSITIVE_INFINITY

   <source lang="java">
 

/*

* Output:

Infinity

*/

public class MainClass {

 public static void main(String args[]) {
   System.out.println(Double.POSITIVE_INFINITY);
 }

}


 </source>
   
  
 
  



Double: shortValue()

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   Double dObj = new Double("10.50");
   byte b = dObj.byteValue();
   System.out.println(b);
   short s = dObj.shortValue();
   System.out.println(s);
   int i = dObj.intValue();
   System.out.println(i);
   float f = dObj.floatValue();
   System.out.println(f);
   double d = dObj.doubleValue();
   System.out.println(d);
 }

} /* 10 10 10 10.5 10.5

  • /


 </source>
   
  
 
  



Double: toString(double d)

   <source lang="java">
 

public class Main {

 public static void main(String[] args) {
   double d = 8.48;
   String s = Double.toString(d);
 }

}


 </source>
   
  
 
  



Double: valueOf(String stringValue)

   <source lang="java">
 

/*

* Output:

10.234

*/

public class MainClass {

 public static void main(String args[]) {
   double degrees = Double.valueOf("10.234").doubleValue();
   System.out.println(degrees);
 }

}


 </source>
   
  
 
  



new Double(double value)

   <source lang="java">
 

/*

* Output:

3.14159 = 3.14159 -> true

* 
 
*/

public class MainClass {

 public static void main(String args[]) {
 Double d1 = new Double(3.14159);
 Double d2 = new Double("314159E-5");
 System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
 }

}



 </source>
   
  
 
  



new Double(String stringValue) "-5"

   <source lang="java">
 

/*

* Output:

3.14159 = 3.14159 -> true

* 
 
*/

public class MainClass {

 public static void main(String args[]) {
 Double d1 = new Double(3.14159);
 Double d2 = new Double("314159E-5");
 System.out.println(d1 + " = " + d2 + " -> " + d1.equals(d2));
 }

}



 </source>