Java prevent E notation in a double:

Five different ways to convert a double to a normal number:

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Runner {
    public static void main(String[] args) {
        double myvalue = 0.00000021d;

        //Option 1 Print bare double.
        System.out.println(myvalue);

        //Option2, use decimalFormat.
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(8);
        System.out.println(df.format(myvalue));

        //Option 3, use printf.
        System.out.printf("%.9f", myvalue);
        System.out.println();

        //Option 4, convert toBigDecimal and ask for toPlainString().
        System.out.print(new BigDecimal(myvalue).toPlainString());
        System.out.println();

        //Option 5, String.format 
        System.out.println(String.format("%.12f", myvalue));
    }
}

This program prints:

2.1E-7
.00000021
0.000000210
0.000000210000000000000001085015324114868562332958390470594167709350585
0.000000210000

Which are all the same value.

Protip: If you are confused as to why those random digits appear beyond a certain threshold in the double value, this video explains: computerphile why does 0.1+0.2 equal 0.30000000000001?

http://youtube.com/watch?v=PZRI1IfStY0

Answer from Eric Leschinski on Stack Overflow
Top answer
1 of 16
321

Java prevent E notation in a double:

Five different ways to convert a double to a normal number:

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class Runner {
    public static void main(String[] args) {
        double myvalue = 0.00000021d;

        //Option 1 Print bare double.
        System.out.println(myvalue);

        //Option2, use decimalFormat.
        DecimalFormat df = new DecimalFormat("#");
        df.setMaximumFractionDigits(8);
        System.out.println(df.format(myvalue));

        //Option 3, use printf.
        System.out.printf("%.9f", myvalue);
        System.out.println();

        //Option 4, convert toBigDecimal and ask for toPlainString().
        System.out.print(new BigDecimal(myvalue).toPlainString());
        System.out.println();

        //Option 5, String.format 
        System.out.println(String.format("%.12f", myvalue));
    }
}

This program prints:

2.1E-7
.00000021
0.000000210
0.000000210000000000000001085015324114868562332958390470594167709350585
0.000000210000

Which are all the same value.

Protip: If you are confused as to why those random digits appear beyond a certain threshold in the double value, this video explains: computerphile why does 0.1+0.2 equal 0.30000000000001?

http://youtube.com/watch?v=PZRI1IfStY0

2 of 16
151

You could use printf() with %f:

double dexp = 12345678;
System.out.printf("dexp: %f\n", dexp);

This will print dexp: 12345678.000000. If you don't want the fractional part, use

System.out.printf("dexp: %.0f\n", dexp);

0 in %.0f means 0 places in fractional part i.e no fractional part. If you want to print fractional part with desired number of decimal places then instead of 0 just provide the number like this %.8f. By default fractional part is printed up to 6 decimal places.

This uses the format specifier language explained in the documentation.

The default toString() format used in your original code is spelled out here.

🌐
Baeldung
baeldung.com › home › java › java numbers › print a double value without scientific notation in java
Print a Double Value Without Scientific Notation in Java | Baeldung
December 28, 2023 - Subsequently, the toPlainString() function converts our complex object into a printable string, providing a precise and easily interpretable representation. Besides eliminating scientific notation, BigDecimal provides features such as customizable ...
🌐
Blogger
marxsoftware.blogspot.com › 2017 › 11 › java-decimals-strings.html
Inspired by Actual Events: Simple String Representation of Java Decimal Numbers without Scientific Notation
The code listing for the Format enum is shown next and this enum demonstrates approaches that can be used with float, double, and BigDecimal to render them without scientific notation. ... /** * Supports rendering of Java numeric types float, double, * and BigDecimal in "default" format and in format that * avoids use of scientific notation. */ public enum Format { DEFAULT { @Override public String fromFloat(final float floatValue) { return String.valueOf(floatValue); } @Override public String fromDouble(final double doubleValue) { return String.valueOf(doubleValue); } @Override public String
🌐
DZone
dzone.com › data engineering › data › string representation of java decimals without scientific notation
String Representation of Java Decimals Without Scientific Notation
November 21, 2017 - Let's take a look at how to print out a Java decimal number in full as a string, without needing to display it in scientific notation. ... Be the first to like this post! It looks like you're not logged in. Sign in to see who liked this post! ... Join the DZone community and get the full member experience. Join For Free · The primary types/objects used for decimal numbers in Java are float/Float, double/Double, and BigDecimal.
🌐
Blogger
self-learning-java-tutorial.blogspot.com › 2020 › 03 › how-to-print-double-value-without.html
Programming for beginners: How to print double value without scientific notation?
March 27, 2020 - Most of the post are example oriented, ... without scientific notation. Approach1: Using System.out.ptintf. ... Approach 2: Using DecimalFormat. ... Approach 3: Using BigDecimal. String value1 = new BigDecimal(d).toPlainString();...
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Simple String Representation of Java Decimal Numbers without Scientific Notation - Java Code Geeks
November 22, 2017 - The primary types/objects used for decimal numbers in Java are float/Float, double/Double, and BigDecimal. Each of these has cases in which its “default” string representation is “computerized scientific notation.” This post demonstrates some simple approaches to provide a string representation of the decimal number in these cases without scientific notation.
🌐
javathinking
javathinking.com › blog › convert-double-to-string-java-without-e
Convert Double to String in Java Without Scientific Notation (E) — javathinking.com
Scientific notation can be confusing for non-technical users, so converting double values to plain decimal strings is essential. When exporting data to a file or a database, you may need to ensure that the numbers are in a consistent and human-readable format. Removing scientific notation makes the data more accessible and easier to process. import java.text.DecimalFormat; public class DoubleToStringWithoutE { public static void main(String[] args) { double number = 12300000000.0; // Create a DecimalFormat object with a pattern DecimalFormat df = new DecimalFormat("#.############"); String result = df.format(number); System.out.println("Using DecimalFormat: " + result); } }
🌐
Codemia
codemia.io › home › knowledge hub › how do i print a double value without scientific notation using java?
How do I print a double value without scientific notation using Java? | Codemia
January 27, 2025 - Below, we will explore a few methods to display double values without resorting to scientific notation, focusing on practical examples. The DecimalFormat class in the java.text package is specifically designed for formatting and parsing numbers with customizable patterns. This class allows you to specify the exact pattern your output should follow. ... 1import java.text.DecimalFormat; 2 3public class Example { 4 public static void main(String[] args) { 5 double largeNumber = 123456789.123456789; 6 7 DecimalFormat df = new DecimalFormat("#.#########"); 8 System.out.println(df.format(largeNumber)); 9 } 10}
Find elsewhere
🌐
Coderanch
coderanch.com › t › 625302 › java › Unable-write-Double-scientific-notation
Unable to write Double value with out scientific notation (Java in General forum at Coderanch)
Kumar Raja wrote:There should be some simple way, which we are forgetting to print the value directly from Double, without scientifc notation. Well you're right, there is. It's called DecimalFormat -- but I see you already know about it.
🌐
CodeVsColor
codevscolor.com › 4 different java programs to convert a double to string without exponential - codevscolor
4 different Java programs to Convert a double to string without exponential - CodeVsColor
May 5, 2023 - Learn to convert a double value to string in Java. We will use four different ways to do the conversion. Using String.valueOf(), String.format(), Double.toString(), by adding an empty string and by using DecimalFormat.
🌐
Coderanch
coderanch.com › t › 417237 › java › format-scientific-notation-double-scientific
format a scientific notation double to a non scientific notation double (Java in General forum at Coderanch)
January 17, 2007 - If you have two doubles: These are exactly equal in all ways. There is no difference at all. What you're asking for is impossible. If you want to convert either of these to a string that doesn't use scientific notation, you need to use the DecimalFormat, or similar methods.
🌐
Coderanch
coderanch.com › t › 388959 › java › disable-scientific-notation
HELP! Need to disable scientific notation (Beginning Java forum at Coderanch)
Look: double myDouble = .00123 ; String myString = new String (myDouble) ; Now whatever value the myDouble value is, it will be recognized as a string in the myString object. It will only be in scientific notation when myDouble is too small too handle anyway. You can't really get around Java's way of storing doubles.
🌐
Iditect
iditect.com › program-example › how-do-i-print-a-double-value-without-scientific-notation-using-java.html
How to print a double value without scientific notation using Java?
In this example, BigDecimal.to... exact decimal values. To print a double value without scientific notation in Java, you can use String.format, DecimalFormat, or BigDecimal....
🌐
Baeldung
baeldung.com › home › kotlin › kotlin numbers › convert double to string removing scientific notation
Convert Double to String Removing Scientific Notation | Baeldung on Kotlin
July 6, 2024 - In this scenario, we initially convert the Double into a BigDecimal instance. Subsequently, we utilize the toPlainString() method to convert it into a string value without scientific notation.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › convert double to string in java
Turning Double into String: Java Techniques
October 1, 2026 - This output shows that the double ... a double to a string without decimal values in Java, you can utilize the DecimalFormat class to control the formatting....
🌐
Programmersought
programmersought.com › article › 90464354073
In java, how to convert a double number to a string without scientific notation - Programmer Sought
DecimalFormat formatted with double, so it will not be converted into a string using scientific notation. ... During the development process, sometimes the number of scientific notation needs to be converted into an intuitive number. At this time, I have to find a way to convert it, but Java ...