Inspectopedia 2025.3 Help

Unpredictable 'BigDecimal' constructor call

Reports calls to BigDecimal constructors that accept a double value. These constructors produce BigDecimal that is equal to the supplied double value. However, because doubles are encoded in the IEEE-754 64-bit double-precision binary floating-point format, the exact value can be unexpected.

For example, new BigDecimal(0.1) yields a BigDecimal object with value 0.1000000000000000055511151231257827021181583404541015625, which is the nearest number to 0.1 representable as a double. To get a BigDecimal that contains the expected value 0.1, use either new BigDecimal("0.1") or BigDecimal.valueOf(0.1).

Example:

class Constructor { void foo() { new BigDecimal(0.1); } }

After the quick-fix is applied:

class Constructor { void foo() { new BigDecimal("0.1"); } }

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.

UnpredictableBigDecimalConstructorCall
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

Inspection ID: UnpredictableBigDecimalConstructorCall

Inspection options

Here you can find the description of settings available for the Unpredictable 'BigDecimal' constructor call inspection, and the reference of their default values.

Ignore constructor calls with variable or method call arguments

Option ID:

ignoreReferences

Default value:

Selected
Ignore constructor calls with multiple literals (e.g. 0.1 + 0.2)

Option ID:

ignoreComplexLiterals

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 UnpredictableBigDecimalConstructorCall

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.3, Qodana for JVM 2025.3,

Last modified: 03 December 2025