The Java float keyword is a primitive data type. It is a single-precision 32-bit IEEE 754 floating point. It is used to declare the variables and methods. It represents the fractional numbers.
Let's see a simple example to display float type variable.
Output:
num1: 5.5 num2: 5.0
In this example, we provide integer value to float variable. Here, compiler implicitly typecast integer to float and display the corresponding value in fractional form.
Output:
num1: 5.0 num2: 10.0
In this example, we provide bigger decimal value.
Output:
num1: 5.812167E8 num2: 7.8368497
In this example, we provide float value to the decimal variable.
Output:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from double to float
In this example, we provide the end range of decimal value.
Output:
num1: 1.4E-45 num2: 3.4028235E38
In this example, we provide the value in scientific notation
Output:
num1: 1873.2 num2: 1873.2
In this example, we create a method returning float value.
Output:
62.5
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India