Inspectopedia 2025.2 Help

Numeric cast that loses precision

Reports cast operations between primitive numeric types that may result in precision loss.

Such casts are not necessarily a problem but may result in difficult to trace bugs if the loss of precision is unexpected.

Example:

int a = 420; byte b = (byte) a;

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

NumericCastThatLosesPrecision
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Numeric issues | Cast

Use the Ignore casts from int to char option to ignore casts from int to char. This type of cast is often used when implementing I/O operations because the read() method of the java.io.Reader class returns an int.

Use the Ignore casts from int 128-255 to byte option to ignore casts of constant values (128-255) from int to byte. Such values will overflow to negative numbers that still fit inside a byte.

Inspection options

Here you can find the description of settings available for the Numeric cast that loses precision inspection, and the reference of their default values.

Ignore casts from int to char

Default value:

Not selected
Ignore casts from int 128-255 to byte

Default value:

Not selected

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection NumericCastThatLosesPrecision

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2025.2, Qodana for JVM 2025.2,

Last modified: 18 September 2025