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 – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

Handling and converting exponential or scientific notation into a readable number format in Java is a common requirement, especially in scientific computing, financial calculations, and data processing. For example, we can convert the exponential notation 1.2345E3 to the standard number format 1234.5, or –1.2345E3 to -1234.5.

In this tutorial, we’ll explore how to convert exponential values into a standard number format.

2. Using DecimalFormat

The DecimalFormat class is part of the java.text package and provides a way to format decimal numbers. Let’s delve into the implementation:

String scientificValueStringPositive = "1.2345E3";
String expectedValuePositive = "1234.5";
String scientificValueStringNegative = "-1.2345E3";
String expectedValueNegative = "-1234.5";

@Test
public void givenScientificValueString_whenUtilizingDecimalFormat_thenCorrectNumberFormat() {

    double scientificValuePositive = Double.parseDouble(scientificValueStringPositive);
    DecimalFormat decimalFormat = new DecimalFormat("0.######");
    String resultPositive = decimalFormat.format(scientificValuePositive);
    assertEquals(expectedValuePositive, resultPositive);

    double scientificValueNegative = Double.parseDouble(scientificValueStringNegative);
    String resultNegative = decimalFormat.format(scientificValueNegative);
    assertEquals(expectedValueNegative, resultNegative);
}

In this test method, we start with two strings representing the scientific notation, one positive 1.2345E3 and one negative -1.2345E3, which correspond to the numbers 1234.5 and -1234.5, respectively. We also set the expected results for both cases.

We parse the strings into doubles using Double.parseDouble(scientificValueString). Then, we create a DecimalFormat object with the pattern 0.######, which ensures up to six decimal places. This pattern works for all magnitudes of the value.

We then call the format() method of the DecimalFormat object with both scientificValuePositive and scientificValueNegative as arguments and store the results in resultPositive and resultNegative.

Finally, we use the assertEquals() method to compare the results with the respective expected values, ensuring that the formatting operations correctly convert the scientific values to the standard number format.

3. Using BigDecimal

The BigDecimal class in the java.math package provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion. Here’s the implementation:

@Test
public void givenScientificValueString_whenUtilizingBigDecimal_thenCorrectNumberFormat() {
    BigDecimal bigDecimalPositive = new BigDecimal(scientificValueStringPositive);
    String resultPositive = bigDecimalPositive.toPlainString();
    assertEquals(expectedValuePositive, resultPositive);

    BigDecimal bigDecimalNegative = new BigDecimal(scientificValueStringNegative);
    String resultNegative = bigDecimalNegative.toPlainString();
    assertEquals(expectedValueNegative, resultNegative);
}

First, we convert both scientificValuePositive and scientificValueNegative to BigDecimal objects directly. After obtaining the BigDecimal representations, we use the toPlainString() method to obtain plain string representations of the numbers.

4. Using String Formatting

Java also provides a way to format strings using the String.format() method. Let’s look at a simple implementation:

@Test
public void givenScientificValueString_whenUtilizingStringFormat_thenCorrectNumberFormat() {
    double scientificValuePositive = Double.parseDouble(scientificValueStringPositive);
    String formatResultPositive = String.format("%.6f", scientificValuePositive).replaceAll("0*$", "").replaceAll("\\.$", "");
    assertEquals(expectedValuePositive, formatResultPositive);

    double scientificValueNegative = Double.parseDouble(scientificValueStringNegative);
    String formatResultNegative = String.format("%.6f", scientificValueNegative).replaceAll("0*$", "").replaceAll("\\.$", "");
    assertEquals(expectedValueNegative, formatResultNegative);
}

In this approach, we parse the strings representing the scientific notation into doubles using Double.parseDouble(scientificValueString).

We then use the format() method of the String object to format the scientific values with up to six decimal places using (%.6f). Further, we remove trailing zeros and a trailing decimal point to ensure the correct representation.

5. Conclusion

In conclusion, by using techniques like DecimalFormat, BigDecimal, and String formatting, we can effectively handle exponential values and present numerical data in a clear and understandable format.

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.
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 – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 1st December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW