Java Integer doubleValue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Integer

Definition

In Java, boxed.doubleValue() returns the number inside an Integer as a primitive double. It is the usual way to start a calculation that needs a decimal answer.

Every int fits exactly in a double, so the conversion never loses precision. The result prints with a decimal part, such as 42.0.

An instance method of java.lang.Integer: call it on an Integer object. Integer lives in java.lang, so no import is needed.

Syntax

Call it on an Integer. It takes no arguments.

Java
Integer total = 17;
Integer count = 4;
int whole = total / count;                    // 4 (integer division)
double exact = total.doubleValue() / count;   // 4.25
CallWhat it does
boxed.doubleValue()The value as a double.
(double) boxedA cast has the same effect on an Integer.
a.doubleValue() / bDivision that keeps the decimal part.
Math.round(x * 10) / 10.0Rounds a result to one decimal place.

Convert before dividing. If both operands are integers, Java divides as integers and throws the decimal part away.

Library declarations
Java
// java.lang.Integer
public double doubleValue()

Parameters

ParameterDescription
NonedoubleValue() takes no parameters.

Return Value

Return ValueDescription
doubleThe same number as a 64-bit double. It is exact for every Integer.

Compare with Similar Methods

Related conversions:

MethodHow it differs
floatValue()A smaller type: it cannot hold every int exactly.
longValue()Widens to long, still a whole number.
intValue()Unwraps back to a plain int.
parseInt(s)Reads text into an int before you convert it.

Java Examples

Example 1 — Calculate an Average with a Decimal Part

Divide two Integer values with and without doubleValue().

Java
public class IntegerDoubleValueDemo {
    public static void main(String[] args) {
        Integer total = 17;
        Integer count = 4;

        System.out.println("integer division: " + (total / count));
        System.out.println("with doubleValue: " + (total.doubleValue() / count));
        System.out.println("converted value:  " + total.doubleValue());
    }
}

How It Works

  1. Two integers divide as integers. 17 divided by 4 is 4 with a remainder of 1, and Java keeps only the 4.
  2. Convert one side. Once the numerator is a double, the whole division is done in decimal arithmetic.
  3. The real average. 17.0 divided by 4 is 4.25.
  4. A whole number still shows a point. total.doubleValue() prints as 17.0, which marks it as a double.

Example 2 — Work Out a Percentage and Round It

Turn a score into a percentage with doubleValue() and round it to one decimal place.

Java
public class IntegerDoubleValuePercent {
    public static void main(String[] args) {
        Integer correct = 37;
        Integer total = 50;

        double percent = correct.doubleValue() / total * 100;
        System.out.println("percent:       " + percent);

        Integer passed = 2;
        Integer all = 3;
        double raw = passed.doubleValue() / all * 100;
        double rounded = Math.round(raw * 10) / 10.0;
        System.out.println("rounded:       " + rounded);
        System.out.println("wrong version: " + (passed / all * 100));
    }
}

How It Works

  1. Decimal first, then scale. 37.0 divided by 50 is 0.74, and times 100 gives 74.0.
  2. A repeating decimal. 2 out of 3 is 66.666..., which Math.round(raw * 10) turns into 667.
  3. Divide by 10.0. Dividing by a double brings the rounded value back to 66.7.
  4. The integer version is wrong. passed / all is 2 / 3, which is 0 in integer arithmetic, so the percentage prints as 0.

Example 3 — See That Every int Fits in a double

Convert the extremes of int to double and back, and see how large values are printed.

Java
public class IntegerDoubleValueExact {
    public static void main(String[] args) {
        Integer max = Integer.MAX_VALUE;
        Integer min = Integer.MIN_VALUE;

        System.out.println("max as double: " + max.doubleValue());
        System.out.println("min as double: " + min.doubleValue());
        System.out.println("back to int:   " + (int) max.doubleValue());
        System.out.println("round trip ok: " + ((int) min.doubleValue() == min));
        System.out.println("million:       " + Integer.valueOf(1000000).doubleValue());
    }
}

How It Works

  1. Scientific notation. Doubles of 10000000 or more print as a number between 1 and 10 times a power of ten, so MAX_VALUE shows as 2.147483647E9.
  2. The sign is kept. MIN_VALUE prints as -2.147483648E9.
  3. No precision is lost. A double has 53 bits of precision, more than the 32 an int needs, so converting back gives the same number.
  4. Smaller values print plainly. One million is below 10000000, so it prints as 1000000.0.

Frequently Asked Questions

It returns the Integer as a primitive double. For example, an Integer holding 42 gives 42.0.
Convert one operand first: a.doubleValue() / b. If both are integers, Java divides as integers and drops the decimal part.
No. Every int fits exactly in a double, so converting back with a cast returns the same number.
Doubles of 10000000 or more are printed in scientific notation, so 2147483647 prints as 2.147483647E9. Use String.format("%.0f", x) to avoid it.
For an Integer they give the same result. The cast (double) boxed unboxes and widens in one step.

Next: equals()

Check whether an Integer equals another object.

equals() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful