Java float data type with example

The float data type

The float is one of the primitive data types supported in Java.

The Java float data type:

  • Takes 32 bits or four bytes of memory.
  • The float is a numeric type with single-precision.
  • The default value of the float variable is 0.0f.

The float data type example

In the following example of using the float, Java data type variable, we have used two variables and shown how you can assign values to those variables. See the example by clicking the link below and read the details below:

Experience this online


As you run code the output will be:

100.25

You can see, a variable a is declared without a value while variable ‘b‘ is assigned a value at the time of declaration. You may define a java float variable by using the keyword: float followed by the variable name.

To assign a value to a float variable, you can use different ways. At the time of declaration use float in brackets followed by the value. Similarly, if you have not assigned a value at the time of declaration, you can assign it later, during the program. Finally, the value of variable ‘a’ is printed by using the java statement.

Also see: Java Data types

Was this article helpful?

Related Articles

Leave A Comment?