Java float keywordThe 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. Points to remember
Examples of Java float keywordExample 1Let's see a simple example to display float type variable. Output: num1: 5.5 num2: 5.0 Example 2In 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 Example 3In this example, we provide bigger decimal value. Output: num1: 5.812167E8 num2: 7.8368497 Example 4In 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 Example 5In this example, we provide the end range of decimal value. Output: num1: 1.4E-45 num2: 3.4028235E38 Example 6In this example, we provide the value in scientific notation Output: num1: 1873.2 num2: 1873.2 Example 7In this example, we create a method returning float value. Output: 62.5
Next TopicJava Keywords
|