- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Format double with new DecimalFormat("0.#####E0") in Java
Firstly, set the double values −
double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920;
Now, format the double values with new DecimalFormat("0.#####E0") −
System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3));
The following is an example −
Example
import java.text.DecimalFormat; public class Demo { public static void main(String[] argv) throws Exception { double d1 = 1.39876; double d2 = 2.39876; double d3 = 0.66920; System.out.println(new DecimalFormat("0.#####E0").format(d1)); System.out.println(new DecimalFormat("0.#####E0").format(d2)); System.out.println(new DecimalFormat("0.#####E0").format(d3)); } }
Output
1.39876E0 2.39876E0 6.692E-1
- Related Articles
- DecimalFormat("0.######E0") in Java
- DecimalFormat("##E0") in Java
- DecimalFormat("###E0") in Java
- Format double type in Java
- DecimalFormat(abc#) in Java
- DecimalFormat("000000E0") in Java
- DecimalFormat("00.00E0") in Java
- DecimalFormat("00E00") in Java
- DecimalFormat("000E00") in Java
- DecimalFormat("0000000000E0") in Java
- Java Program to format hour in H (0-23) format in Java
- String format for Double in C#
- Format Calendar with String.format() in Java
- Format date with DateFormat.SHORT in Java
- Format time with DateFormat.SHORT in Java

Advertisements