English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Underflow of data types in Java

Underflow occurs when the given value is less than the maximum specified size of the data type. Underflow conditions may cause errors, or the implementation of the current programming language can handle it automatically.

To demonstrate underflow of data types, I take the double data type as an example. The Double data type is a single precision64Bit IEEE 754Floating point.

The following program demonstrates underflow of data types in Java.

Example

public class Demo {
   public static void main(String[] args) {
      System.out.println("Displaying Underflow... ");
      double val1 = 3.2187E-320;
      System.out.println(val1/1000000);
   }
}

Output Result

Displaying Underflow...
0.0

In the above program, initialize the double variable as follows.

double val1 = 3.2187E-320;

After that, perform division operations on it to check for underflow.

val1/1000000

It returns the following content.

0.0