Java Integer floatValue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Integer

Definition

In Java, boxed.floatValue() returns the number inside an Integer as a primitive float. A float uses 32 bits and has only about 7 significant decimal digits.

That is enough for small numbers, but a float cannot hold every int exactly: above 16777216 (224) some whole numbers are rounded to a nearby value. When you need exact conversions, use doubleValue() instead.

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 boxed = 123;
float a = boxed.floatValue();      // 123.0
Integer big = 16777217;
float b = big.floatValue();        // 1.6777216E7 (rounded!)
CallWhat it does
boxed.floatValue()The value as a float.
(float) boxedA cast has the same effect.
boxed.doubleValue()Exact for every int; use it when precision matters.
(int) fConverts a float back to an int, cutting off any decimal part.

Values up to 16777216 convert exactly. Above that, floatValue() may round the number to the nearest value that a float can store.

Library declarations
Java
// java.lang.Integer
public float floatValue()

Parameters

ParameterDescription
NonefloatValue() takes no parameters.

Return Value

Return ValueDescription
floatThe value as a 32-bit float. It may be rounded when the absolute value is above 16777216.

Compare with Similar Methods

Related conversions:

MethodHow it differs
doubleValue()Twice the precision; exact for every int.
longValue()Keeps the number whole and exact.
intValue()Unwraps to a plain int.
shortValue()Narrows instead of widening, and may lose the high bits.

Java Examples

Example 1 — Convert Small Integers to float

Convert a few ordinary values and see how a float prints.

Java
public class IntegerFloatValueDemo {
    public static void main(String[] args) {
        Integer[] numbers = {123, -42, 1000000, 0};

        for (Integer number : numbers) {
            System.out.println(number + " -> " + number.floatValue());
        }
        Integer ten = 10;
        System.out.println("10 / 4 as float: " + ten.floatValue() / 4);
    }
}

How It Works

  1. A point and a zero. Whole numbers print with .0, so 123 becomes 123.0.
  2. Negative and zero. The sign is kept, and zero prints as 0.0.
  3. Small enough to be exact. One million is far below 16777216, so it converts exactly and prints as 1000000.0.
  4. Decimal division. Starting with a float makes 10 divided by 4 equal 2.5.

Example 2 — See Where float Starts to Lose Precision

Convert numbers around 16777216 and see which ones survive the trip through float.

Java
public class IntegerFloatValuePrecision {
    public static void main(String[] args) {
        Integer[] numbers = {16777215, 16777216, 16777217, 16777219};

        for (Integer number : numbers) {
            float f = number.floatValue();
            long back = (long) f;
            System.out.println(number + " -> " + back + " (exact: " + (back == number) + ")");
        }
        Integer big = 16777217;
        System.out.println("as double: " + (long) big.doubleValue());
    }
}

How It Works

  1. Up to 224 is exact. 16777215 and 16777216 come back unchanged.
  2. 16777217 is rounded. A float has 24 bits of precision, so above 16777216 it can only store every second whole number, and 16777217 becomes 16777216.
  3. 16777219 rounds too. It lies between 16777218 and 16777220, and rounding to even gives 16777220.
  4. A double is safe. The same 16777217 converted through doubleValue() comes back exactly.

Example 3 — Compare float and double Results

Divide 1 by 3 in float and in double to see how much more precise double is.

Java
public class IntegerFloatValueCompare {
    public static void main(String[] args) {
        Integer one = 1;
        Integer three = 3;

        float f = one.floatValue() / three;
        double d = one.doubleValue() / three;

        System.out.println("float:  " + f);
        System.out.println("double: " + d);
        System.out.println("float as double: " + (double) f);
        System.out.println("same:   " + (f == d));
    }
}

How It Works

  1. Same calculation, two types. Both lines compute 1 divided by 3, but one starts with floatValue() and the other with doubleValue().
  2. float is short. It prints about 8 digits: 0.33333334.
  3. double is longer. It prints 16 digits: 0.3333333333333333.
  4. They are not equal. Widening the float back to double reveals its hidden error, so the comparison is false.

Frequently Asked Questions

It returns the Integer as a primitive float. For example, an Integer holding 123 gives 123.0.
For numbers above 16777216 it can. A float has only 24 bits of precision, so 16777217 becomes 16777216.
Prefer double, which is exact for every int. Use float only when memory matters and the values are small.
Use a cast: (int) f. It cuts off the decimal part. Use Math.round(f) if you want the nearest whole number.
A float stores about 7 to 8 significant digits, so the last digit is rounded. A double prints 0.3333333333333333.

Next: getInteger()

Read an int from a system property.

getInteger() 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.

7 people found this page helpful