Java

What Is Float Keyword In Java?

In Java, the floating point data type is designated by the float keyword. The float data type has a range of 3.4e-038 to 3.4e+038. This range is expressed in scientific notation, where the number 3.4e+038 corresponds to 34 zeroes and 37 ones (see the example at the end of this post to learn how this notation works)

public class JavaExample {
  public static void main(String[] args) {
    float num = 45.789f; //float value ends with f
    System.out.println(num);
  }
}

Output:

45.789

Note: Use the double data type for numbers that are bigger than the higher range of float and smaller than the lower range of float.

Example of float keyword

Check out how scientific notation functions. This will make it easier for you to comprehend the float data type’s range, which is indicated in the notation at the beginning of the text.

public class JavaExample {
  public static void main(String[] args) {
    //scientific notation values
    float num = 15.55e+03f;
    float num2 = 15.55e-03f;
    System.out.println(num);
    System.out.println(num2);
  }
}

Output:

15550.0
0.01555

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button