---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 20 Edition"
java_version: 20
chapter: "Chapter 5. Conversions and Contexts"
section: "5.1.2"
heading: "5.1.2. Widening Primitive Conversion"
parent: "5.1. Kinds of Conversion"
source: https://docs.oracle.com/javase/specs/jls/se20/html/jls-5.html#jls-5.1.2
id: "5.1.2"
url: https://jvm.obfuscated.software/jls/se20/5.1.2.html
raw: https://jvm.obfuscated.software/jls/se20/5.1.2.md
---

# 5.1.2. Widening Primitive Conversion

19 specific conversions on primitive types are called the *widening primitive conversions*:

- `byte` to `short`, `int`, `long`, `float`, or `double`
- `short` to `int`, `long`, `float`, or `double`
- `char` to `int`, `long`, `float`, or `double`
- `int` to `long`, `float`, or `double`
- `long` to `float` or `double`
- `float` to `double`

A widening primitive conversion does not lose information about the overall magnitude of a numeric value in the following cases, where the numeric value is preserved exactly:

- from an integral type to another integral type
- from `byte`, `short`, or `char` to a floating-point type
- from `int` to `double`
- from `float` to `double`

A widening primitive conversion from `int` to `float`, or from `long` to `float`, or from `long` to `double`, may result in *loss of precision*, that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using the round to nearest rounding policy ([§15.4](15.4.md)).

A widening conversion of a signed integer value to an integral type T simply sign-extends the two's-complement representation of the integer value to fill the wider format.

A widening conversion of a `char` to an integral type T zero-extends the representation of the `char` value to fill the wider format.

A widening conversion from `int` to `float`, or from `long` to `float`, or from `int` to `double`, or from `long` to `double` occurs as determined by the rules of IEEE 754 for converting from an integer format to a binary floating-point format.

A widening conversion from `float` to `double` occurs as determined by the rules of IEEE 754 for converting between binary floating-point formats.

Despite the fact that loss of precision may occur, a widening primitive conversion never results in a run-time exception ([§11.1.1](11.1.1.md)).

**Example 5.1.2-1. Widening Primitive Conversion**

```
class Test {
    public static void main(String[] args) {
        int big = 1234567890;
        float approx = big;
        System.out.println(big - (int)approx);
    }
}
```

This program prints:

```
-46
```

thus indicating that information was lost during the conversion from type `int` to type `float` because values of type `float` are not precise to nine significant digits.
