eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

1. Introduction

In our daily tasks, we may often come across challenges to format double values. One such challenge could be printing a double value, avoiding scientific notation. Even though this method helps us express large and small values more compactly, there are situations where the default scientific notation might not be the most practical choice. In such cases, alternative approaches may need to be considered for a more suitable representation.

In this tutorial, we’ll explore various methods to print a double value without scientific notation in Java.

2. About Scientific Notation

Scientific notation consists of two components: a coefficient and an exponent. Typically, a decimal number between 1 and 10 is the coefficient, while the exponent indicates the power of 10 by which the system multiplies the coefficient.

In Java, scientific notation is often represented using the “e” notation, where “e” stands for exponent:

double largeNumber = 256450000d;
System.out.println("Large Number: " + largeNumber);

double smallNumber = 0.0000046d;
System.out.println("Small Number: " + smallNumber);

Running the code from above will output to the console two scientifically notated numbers:

Large Number: 2.5645E8
Small Number: 4.6E-6

The first number was represented as 2.5645 * 108, and the second one as 4.6 * 10-6 using the “e” notation. This compact writing can help us many times, but it can also mislead us. Due to this, in the following, we’ll see some methods to eliminate it.

3. Using the DecimalFormat Class

We can easily control how numeric values are shown using the DecimalFormat class. Also, it allows us to specify formatting patterns. We can define the desired decimal places and other formatting details to suit our application’s requirements:

DecimalFormat df = new DecimalFormat("#.###########");
double largeNumber = 256450000d;
System.out.println("Large Number: " + df.format(largeNumber));
double smallNumber = 0.0000046d;
System.out.println("Small Number: " + df.format(smallNumber));

We created a pattern that consists of a sequence of special characters, possibly combined with text. In our examples, we opted for the ‘#’ character, which displays a digit when one is provided and nothing otherwise. If we run the code from above, we will print the numbers on the console without scientific notation:

Large Number: 256450000
Small Number: 0.0000046

We can see that even if we put only one character for the integer part, it will always be retained, regardless of whether the pattern is smaller than the actual number.

4. Using printf() Method

The printf() method in the PrintStream class offers a dynamic and straightforward way to format output. It closely resembles the traditional C-style printf() function.

We’ll use the %f specifier to shape the presentation of floating-point numbers assertively:

double largeNumber = 256450000d;
System.out.printf("Large Number: %.7f", largeNumber);
System.out.println();
double smallNumber = 0.0000046d;
System.out.printf("Small Number: %.7f", smallNumber);

In this case, we’ll output:

Large Number: 256450000.0000000
Small Number: 0.0000046

If the number has no decimals, it will fill the decimal places with zeros. Also, if we don’t specify the number of decimals, it will print, by default, six decimal places.

If we print our small number without explicitly specifying the number of decimals:

System.out.printf("Small Number: %f", smallNumber);

Because the value has more decimals than specified in the format, the printf() method will round the value:

Small Number: 0.000005

5. Using BigDecimal

BigDecimal is ideal when dealing with financial calculations, scientific computations, or any application where maintaining precision is crucial. Unlike primitive data types or double values, which can lead to precision loss due to the inherent limitations of binary floating-point representation, BigDecimal allows us to specify the exact precision we need.

When working with BigDecimal, the concept of scientific notation is inherently different. The class itself allows us to work with arbitrary precision numbers without resorting to scientific notation, providing a straightforward solution to the challenges posed by default representations:

double largeNumber = 256450000d;
System.out.println("Large Number: " + BigDecimal.valueOf(largeNumber).toPlainString());
double smallNumber = 0.0000046d;
System.out.println("Small Number: " + BigDecimal.valueOf(smallNumber).toPlainString());

In this example, we employ the BigDecimal.valueOf() method to convert a double value with scientific notation into a BigDecimal. 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 rounding modes, which can be crucial in financial applications. The ability to precisely control the number of decimal places and handle extremely large or small numbers makes BigDecimal a go-to choice for developers prioritizing accuracy and precision in their Java applications.

6. Using String.format()

The String.format() method shapes a String using a format string and arguments.

Both String.format() and printf() methods use the java.util.Formatter class and share the exact underlying mechanism for formatting, providing a convenient way to produce well-structured output. However, there are subtle differences in their application and usage.

double largeNumber = 256450000d;
String formattedLargeNumber = String.format("%.7f", largeNumber);
System.out.println("Large Number: " + formattedLargeNumber);
double smallNumber = 0.0000046d;
String formattedSmallNumber = String.format("%.7f", smallNumber);
System.out.println("Small Number: " + formattedSmallNumber);

As can be seen in the example above, the String.format() method returns a formatted string rather than directly printing it to the console. We can store the formatted string in a variable, therefore making it easier for us to handle it further or use it in different contexts. Both methods share the same format specifiers, so the syntax for formatting remains consistent between them.

7. Conclusion

In this article, we saw multiple avenues for avoiding scientific notation when printing double values. Even more, we’ve seen many ways to format numbers, small or large, using different methods. We also played with format specifiers to ensure our desired level of detail.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments