In this core java tutorial we will learn how to convert double primitive type to String in java and convert double object to String with program and examples in java. We will also understand When to use convert String to double primitive type and when when to convert String to double object in java.
Programs to convert double to String in java -
- Program/Example 1 to How to convert double primitive type to String in java.
- Program/Example 2 to How to convert double object to String in java
Program/Example 1 to How to convert double primitive type to String in java.
String.valueOf(double) method converts double primitive type to String in java.
package convertDoubleToStringPkg;
public class ConvertDoubleToStringExample1 {
public static void main(String[] args) {
double d = 12d;
String string = String.valueOf(d);
System.out.println("string = "+string);
}
}
/*OUTPUT
string = 12.0
*/
|
Program/Example 2 to How to convert double object to String in java
toString() method of java.lang.Double class convert double object to String in java.
package convertDoubleToStringPkg;
public class ConvertDoubleObjectToStringExample2 {
public static void main(String[] args) {
Double doubleObject = 12d;
String string = doubleObject.toString();
System.out.println("string = "+string);
}
}
/*OUTPUT
string = 12.0
*/
|
Summary -
In this core java tutorial we learned conversion of double primitive type to String in java and convert double object to String with program and examples in java. We also understood when to use convert String to double primitive type and when when to convert String to double object in java.
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy(JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>