Double to String conversion
Two ways to convert double to String:
1: Using valueOf() method
public static String valueOf(double d)
We can convert the double primitive to String by calling valueOf() method of String class. This method returns the string representation of the double argument.
We can convert the double primitive to String by calling valueOf() method of String class. This method returns the string representation of the double argument.
double var = 22.22; String strg = String.valueOf(var);
2: Using toString() method
public String toString( ):
This is the another method that can be used to convert double to String. This method returns a string representation of the Double object. The primitive double value represented by this object is converted to a string.
This is the another method that can be used to convert double to String. This method returns a string representation of the Double object. The primitive double value represented by this object is converted to a string.
double var = 33.33; String str = Double.toString(var);
Example:
public class DoubleToString { public static void main(String[] args) { // Method 1: using valueOf() method of String class double dvar = 201.11; String strg = String.valueOf(dvar); System.out.println("String is: "+strg); // Method 2: using toString() method of Double class double dvar1 = 200.202; String strg1 = Double.toString(dvar1); System.out.println("String2 is: "+strg1); } }
Output:
String is: 201.11 String2 is: 200.202
Really nice blog,i enjoyed your infomations. Thank you and i will expect more in future.
ReplyDeleteJAVA Training in Chennai
Best JAVA Training institute in Chennai
Python Training in Chennai
Selenium Training in Chennai
Android Training in Chennai
Big data training in chennai
JAVA Training in Annanagar
java training in chennai anna nagar
Great Blog!!! Presentation was really good... thanks for sharing with us...
ReplyDeleteAndroid Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery
Wow, very nice blog. really it is very interesting and helpful. Please keep sharing such type of information. Thanks!
ReplyDelete