
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Double Value to Java String Using Append Method
The append method of the StringBuilder or StringBuffer objects accept a boolean or, char or, char array or, double or, float or, int or, long or, String value as parameter and adds it to the current object.
You can append the required double value to the method and retrieve a String from obtained StringBuffer (or, StringBuilder) objects.
Example
import java.util.Scanner; public class ConversionOfDouble { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a double value:"); double d = sc.nextDouble(); StringBuffer sb = new StringBuffer(); sb.append(d); String result = sb.toString(); System.out.println("The result is: "+result); } }
Output
Enter a double value: 2548.2325 The result is: 2548.2325
Example
public class Test { public static void main(String args[]) { double val = 5698.336; StringBuffer sb = new StringBuffer(); sb.append(val); String result = sb.toString(); System.out.println(result); } }
Output
5698.336
Advertisements