You can try BigDecimal for this purpose

Double toBeTruncated = new Double("3.5789055");

Double truncatedDouble = BigDecimal.valueOf(toBeTruncated)
    .setScale(3, RoundingMode.HALF_UP)
    .doubleValue();
Answer from Neel on Stack Overflow
๐ŸŒ
Apache
db.apache.org โ€บ derby โ€บ docs โ€บ 10.1 โ€บ ref โ€บ rrefsqljdoubleprecision.html
DOUBLE PRECISION
DOUBLE can be used synonymously with DOUBLE PRECISION. ... These limits are different from the java.lang.DoubleJava type limits.
Discussions

Java Double Precision
I found this useful the first time I encountered the strangeness of floating-point values: https://floating-point-gui.de/ Basically, it boils down to you can't represent an infinite continuum of real numbers using a finite number of bits. More on reddit.com
๐ŸŒ r/java
25
14
August 24, 2020
Java Programming Help: How to set Precision for double value | Codersarts
You can set Precision for double value either via BigDecimal or DecimalFormat, depending on what you want to do with the value later. ... package com.codersarts; import java.text.DecimalFormat; public class DecimalFormatExample { // setting precision upto 2 decimal point private static ... More on codersarts.com
๐ŸŒ codersarts.com
August 10, 2019
Java Double Precision : java
I came across a piece of code in a legacy Java 8 application at work which adds two doubles and gives out a double. I observed that the resulting... More on i.reddit.com
๐ŸŒ r/java
[Java] Precision related question on double value vs BigDecimal object
In Java, do double values lose precision only when you perform math on multiple numbers? More on reddit.com
๐ŸŒ r/learnprogramming
11
1
March 4, 2013

You can try BigDecimal for this purpose

Double toBeTruncated = new Double("3.5789055");

Double truncatedDouble = BigDecimal.valueOf(toBeTruncated)
    .setScale(3, RoundingMode.HALF_UP)
    .doubleValue();
Answer from Neel on Stack Overflow
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Double-precision_floating-point_format
Double-precision floating-point format - Wikipedia
January 9, 2026 - Most implementations provide SINGLE-FLOATs and DOUBLE-FLOATs with the other types appropriate synonyms. Common Lisp provides exceptions for catching floating-point underflows and overflows, and the inexact floating-point exception, as per IEEE 754. No infinities and NaNs are described in the ANSI standard, however, several implementations do provide these as extensions. On Java before version 1.2, every implementation had to be IEEE 754 compliant.
๐ŸŒ
Medium
medium.com โ€บ @sachinkg12 โ€บ why-double-loses-precision-and-how-to-avoid-it-in-java-19066974ddd7
Why double Loses Precision and How to Avoid It in Java | by Sachin Gupta | Medium
January 22, 2025 - The double data type in Java follows the IEEE 754 standard for floating-point arithmetic. It represents numbers in binary format using: ... Finite Precision: double can only represent numbers up to 15โ€“17 decimal digits accurately.
Find elsewhere
๐ŸŒ
TheServerSide
theserverside.com โ€บ blog โ€บ Coffee-Talk-Java-News-Stories-and-Opinions โ€บ Java-double-precision-2-decimal-places-example-float-range-math-jvm
Java double decimal precision
The precision of a double in Java is 10-324 decimal places, although true mathematical precision can suffer due to issues with binary arithmetic.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javadb โ€บ 10.10.1.2 โ€บ ref โ€บ rrefsqljdoubleprecision.html
DOUBLE PRECISION data type
The DOUBLE PRECISION data type provides 8-byte storage for numbers using IEEE floating-point notation.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ float vs double in java - difference you should know
Float Vs Double in Java - Difference You Should Know - Scaler Topics
March 27, 2024 - The double keyword in Java is also a primitive data type, and its size limit is 8 byte or 64 bits double-precision IEEE 754 floating-point number, that is it can allow up to 15 digits precision after the decimal.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ java โ€บ double
double Keyword in Java: Usage & Examples
The double keyword in Java is a primitive data type that represents a double-precision 64-bit IEEE 754 floating point.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_data_types_numbers.asp
Java Numbers
The precision of float is only 6-7 decimal digits, while double variables have a precision of about 16 digits.
๐ŸŒ
Daily.dev
app.daily.dev โ€บ posts โ€บ double-precision-issue-in-java-ermzy36qb
Double Precision Issue in Java
September 21, 2023 - daily.dev is the easiest way to stay updated on the latest programming news. Get the best content from the top tech publications on any topic you want.
๐ŸŒ
Quora
quora.com โ€บ Why-does-Java-use-double-for-floating-point-numbers-instead-of-long-for-scientific-calculations
Why does Java use double for floating point numbers instead of long for scientific calculations? - Quora
Answer: Usage of floating point arithmetics in scientific calculations is not related to Java. Floating points are able to represent real number with varying precision for different magnitudes: number with smaller magnitudes are represented with higher precision and numbers with large magnitudes...
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ java โ€บ javase โ€บ 24 โ€บ docs โ€บ api โ€บ java.base โ€บ java โ€บ lang โ€บ Double.html
Double (Java SE 24 & JDK 24)
July 15, 2025 - Values of the float type have 24 bits of precision and values of the double type have 53 bits of precision. Therefore, since 0.1 is a repeating fraction in base 2 with a four-bit repeat, 0.1f != 0.1d.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-store-more-precise-numbers-than-double-in-Java
How to store more precise numbers than double in Java - Quora
Answer (1 of 2): Yes, use java.math.BigDecimal class. It can represent numbers with great precision. If you just need huge integers, you can use java.math.BigInteger instead. They both extend java.math.Number.
๐ŸŒ
TheServerSide
theserverside.com โ€บ blog โ€บ Coffee-Talk-Java-News-Stories-and-Opinions โ€บ Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits. A double is twice the size of a float โ€” thus the term double. In Java, the Float and Double wrapper classes have two properties that ...
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ how to round double / float value to 2 decimal places
Java โ€“ How to round double / float value to 2 decimal places - Mkyong.com
February 25, 2025 - For situations where we need more precision, such as scientific calculations, we can adjust the multiplier accordingly: double input = 1205.6358; double roundedValue = Math.round(input * 1000.0) / 1000.0; System.out.println("Rounded value : " + roundedValue); ... Founder of Mkyong.com, passionate Java and open-source technologies.
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ java double precision
r/java on Reddit: Java Double Precision
August 24, 2020 -

I came across a piece of code in a legacy Java 8 application at work which adds two doubles and gives out a double. I observed that the resulting doubles for various inputs had variable number of digits after the decimal point. Some were very precise with 12 digits after the decimal point and some had merely a digit after the decimal point.

Iโ€™m curious to know what factors affect certain doubles to be so very precise and certain doubles not as much.

Examples:

double one = 3880.95; double two = 380.9; Result: 4261.849999999999

double one = 1293.65; double two = 1293.6; Result: 2587.25

๐ŸŒ
Codersarts
codersarts.com โ€บ forum โ€บ java-programming-help โ€บ java-programming-help-how-to-set-precision-for-double-value
Java Programming Help: How to set Precision for double value | Codersarts
August 10, 2019 - You can set Precision for double value either via BigDecimal or DecimalFormat, depending on what you want to do with the value later. ... package com.codersarts; import java.text.DecimalFormat; public class DecimalFormatExample { // setting precision upto 2 decimal point private static ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-set-precision-for-double-values-in-java
How to Set Precision For Double Values in Java? - GeeksforGeeks
July 12, 2025 - From the above output, it is clear that precision of 20 digits is been carried out for the first entry whereas precision to 5 digits is carried out on input double value. ... // Demonstrating the precision modifier import java.util.*; class ...