
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to convert a double value into a Java String using format method?
This method accepts a format String and arguments (varargs) and returns a String object of the given variable(s) in the specified format.
You can format a double value into a String using the format() method. To it pass “%f” as the format string (along with the required double value).
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(); String result = String.format("%f", d); System.out.println("The result is: "+result); } }
Output
Enter a double value: 2548.2325 The result is: 2548.2325
Example
public class Sample{ public static void main(String args[]){ double val = 22588.336; String str = String.format("%f", val); System.out.println(str); } }
Output
22588.336000
- Related Questions & Answers
- How to convert a double value into a Java String using append method?
- Java Program to convert Double into String using toString() method of Double class
- How to convert a double value to String in Java?
- Convert double value to string in Java
- How do I convert a double into a string in C++?
- How to Convert Double to String to Double in Java?
- How to convert a Double array to a String array in java?
- Convert a String to a double type number in Java
- Convert double to string in Java
- Convert String to Double in Java
- How to convert a String into int in Java?
- Java Program to convert String to Double
- Java methods to convert Double to String
- How to convert a string into upper case using JavaScript?
- How to correctly convert a date format into a MySQL date?
Advertisements