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
🌐
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 ...
🌐
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.
🌐
Javacodemonk
javacodemonk.com › set-precision-and-scale-for-a-double-value-in-java-9c8d56f4
Precision and scale for a Double in java
August 3, 2020 - If you still want to lose the precision simply divide the number by 10 to the power precision. There are multiple ways in Java to round the double value to certain scale, as mentioned in the below example,
🌐
Baeldung
baeldung.com › home › java › java numbers › double precision issue in java
Double Precision Issue in Java | Baeldung
January 8, 2024 - According to the standard, the representation of a double-precision data type consists of three parts: Sign bit – contains the sign of the number (1 bit) Exponent – controls the scale of the number (11 bits) Fraction (Mantissa) – contains the significant digits of the number (52 bits) Now, to understand the double precision issue, let’s perform a simple addition of two decimal numbers:
Top answer
1 of 16
183

As others have mentioned, you'll probably want to use the BigDecimal class, if you want to have an exact representation of 11.4.

Now, a little explanation into why this is happening:

The float and double primitive types in Java are floating point numbers, where the number is stored as a binary representation of a fraction and a exponent.

More specifically, a double-precision floating point value such as the double type is a 64-bit value, where:

  • 1 bit denotes the sign (positive or negative).
  • 11 bits for the exponent.
  • 52 bits for the significant digits (the fractional part as a binary).

These parts are combined to produce a double representation of a value.

(Source: Wikipedia: Double precision)

For a detailed description of how floating point values are handled in Java, see the Section 4.2.3: Floating-Point Types, Formats, and Values of the Java Language Specification.

The byte, char, int, long types are fixed-point numbers, which are exact representions of numbers. Unlike fixed point numbers, floating point numbers will some times (safe to assume "most of the time") not be able to return an exact representation of a number. This is the reason why you end up with 11.399999999999 as the result of 5.6 + 5.8.

When requiring a value that is exact, such as 1.5 or 150.1005, you'll want to use one of the fixed-point types, which will be able to represent the number exactly.

As has been mentioned several times already, Java has a BigDecimal class which will handle very large numbers and very small numbers.

From the Java API Reference for the BigDecimal class:

Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore (unscaledValue × 10^-scale).

There has been many questions on Stack Overflow relating to the matter of floating point numbers and its precision. Here is a list of related questions that may be of interest:

  • Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?
  • How to print really big numbers in C++
  • How is floating point stored? When does it matter?
  • Use float or decimal for accounting application dollar amount?

If you really want to get down to the nitty gritty details of floating point numbers, take a look at What Every Computer Scientist Should Know About Floating-Point Arithmetic.

2 of 16
111

When you input a double number, for example, 33.33333333333333, the value you get is actually the closest representable double-precision value, which is exactly:

33.3333333333333285963817615993320941925048828125

Dividing that by 100 gives:

0.333333333333333285963817615993320941925048828125

which also isn't representable as a double-precision number, so again it is rounded to the nearest representable value, which is exactly:

0.3333333333333332593184650249895639717578887939453125

When you print this value out, it gets rounded yet again to 17 decimal digits, giving:

0.33333333333333326
🌐
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 - ... package com.codersarts; import java.text.DecimalFormat; public class DecimalFormatExample { // setting precision upto 2 decimal point private static DecimalFormat df = new DecimalFormat("#.##"); public static void main(String[] args) { double piValue = 3.14159265359; System.out.println("double ...
Find elsewhere
🌐
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

🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Format-double-Java-printf-example
How to format a Java double with printf example
Precision is to two decimal places. A comma groups large numbers by the thousands. It is a common requirement to format currencies to two decimal places. You can easily achieve this with the Java printf function.
🌐
DZone
dzone.com › data engineering › data › why you should never use float and double for monetary calculations
Why You Should Never Use Float and Double for Monetary Calculations
August 21, 2018 - For example, 12.345 has the precision of 5 (total digits) and the scale of 3 (number of digits right of the decimal). We might get exponentiation in the calculation result if we do not follow some best practices while using BigDecimal. Below is the code snippet that shows a helpful usage example of handling the calculation result with BigDecimal. ... import java.math.BigDecimal; public class BigDecimalForCurrency { public static void main(String[] args) { int scale = 4; double value = 0.11111; BigDecimal tempBig = new BigDecimal(Double.toString(value)); tempBig = tempBig.setScale(scale, BigDecimal.ROUND_HALF_EVEN); String strValue = tempBig.stripTrailingZeros().toPlainString(); System.out.println("tempBig = " + strValue); } }
🌐
Coderanch
coderanch.com › t › 374653 › java › Double-precision
Double precision (Java in General forum at Coderanch)
Ref: http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigDecimal.html http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html [ September 24, 2004: Message edited by: marc weber ] "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org ... Boost this thread! ... Single and double precision numbers...
🌐
The Floating-Point Guide
floating-point-gui.de › languages › java
The Floating-Point Guide - Floating-point cheat sheet for Java
float f = 0.1f; // 32 bit float, note f suffix double d = 0.1d; // 64 bit float, suffix optional · The strictfp keyword on classes, interfaces and methods forces all intermediate results of floating-point calculations to be IEEE 754 values as well, guaranteeing identical results on all platforms. Without that keyword, implementations can use an extended exponent range where available, resulting in more precise results and faster execution on many common CPUs. Java has an arbitrary-precision decimal type named java.math.BigDecimal, which also allows to choose the rounding mode.
🌐
Coderanch
coderanch.com › t › 442773 › java › Precision-double-literals
Precision for double literals (Java in General forum at Coderanch)
The answer is that the first 15 decimal places are guaranteed to be correct and the remaining decimal places are likely to have precision errors in the binary representation of the double. So Java automatically truncates double values to the first 15 decimal places when displaying them.
Top answer
1 of 4
14

@PeterLawrey states max precision in 15.

That's actually not what he stated at all. What he stated was:

double has 15 decimal places of accuracy

and he is wrong. They have 15 decimal digits of accuracy.

The number of decimal digits in any number is given by its log to the base 10. 15 is the floor value of log10(253-1), where 53 is the number of bits of mantissa (including the implied bit), as described in the Javadoc and IEEE 754, and 253-1 is therefore the maximum possible mantissa value. The actual value is 15.954589770191003298111788092734 to the limits of the Windows calculator.

He is quite wrong to describe it as 'decimal places of accuracy'. A double has 15 decimal digits of accuracy if they are all before the decimal point. For numbers with fractional parts you can get many more than 15 digits in the decimal representation, because of the incommensurability of decimal and binary fractions.

2 of 4
2

Run this code, and see where it stops

public class FindPrecisionDouble {
  static public void main(String[] args) {
    double x = 1.0;
    double y = 0.5;
    double epsilon = 0;
    int nb_iter = 0;
    while ((nb_iter < 1000) && (x != y)) {
        System.out.println(x-y);
        epsilon = Math.abs(x-y);
        y = ( x + y ) * 0.5;
    }
    final double prec_decimal = - Math.log(epsilon) / Math.log(10.0);
    final double prec_binary = - Math.log(epsilon) / Math.log(2.0);
    System.out.print("On this machine, for the 'double' type, ");
    System.out.print("epsilon = " );
    System.out.println( epsilon );
    System.out.print("The decimal precision is " );
    System.out.print( prec_decimal );
    System.out.println(" digits" );
    System.out.print("The binary precision is " );
    System.out.print( prec_binary );
    System.out.println(" bits" );
  }
}

Variable y becomes the smallest value different than 1.0. On my computer (Mac Intel Core i5), it stops at 1.1102...E-16. It then prints the precision (in decimal and in binary).

As stated in https://en.wikipedia.org/wiki/Machine_epsilon, floating-point precision can be estimated with the epsilon value. It is "the smallest number that, when added to one, yields a result different from one" (I did a small variation: 1-e instead of 1+e, but the logic is the same)

I'll explain in decimal: if you have a 4-decimals precision, you can express 1.0000 - 0.0001, but you cannot express the number 1.00000-0.00001 (you lack the 5th decimal). In this example, with a 4-decimals precision, the epsilon is 0.0001. The epsilon directly measures the floating-point precision. Just transpose to binary.

Edit Your question asked "How to determine...". The answer you were searching were more an explanation of than a way to determine precision (with the answer you accepted). Anyways, for other people, running this code on a machine will determine the precision for the "double" type.

🌐
CopyProgramming
copyprogramming.com › howto › java-how-to-set-precision-for-double-value
Java: Setting Precision for Double Values in Java - A Guide
June 6, 2023 - 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. ... The functions available through cqlsh are solely intended for data presentation purposes.
🌐
Coderanch
coderanch.com › t › 395128 › java › Setting-precision-double
Setting precision for a double value (Beginning Java forum at Coderanch)
I've a doubt concerning a double value. Is it possible to set it's precision to 2, i.e the number to be displayed only upto 2 decimal places.
🌐
Baeldung
baeldung.com › home › java › java numbers › how to round a number to n decimal places in java
How to Round a Number to N Decimal Places in Java | Baeldung
September 24, 2025 - Java provides two primitive types that we can use for storing decimal numbers: float and double. Double is the default type: ... However, we should never use either type for precise values like currencies.