Float Java

 
The float data type represents a single-precision 32-bit IEEE 754 floating point.

Range: 3.4e−038 to 3.4e+038.

Program to declare and use Java primitive float variable.

/**
 * Program to declare and use Java primitive float variable.
 * @author W3spoint
 */
public class DataTypeFloatExample {	
  public static void main(String args[]){ 
	//Declare float type variables.
	float f1 = 32.454f;
	float f2 = 178.44f;
 
        //Print variables value.
        System.out.println("f1 Value: " + f1);
        System.out.println("f2 Value: " + f2);
 
        //Print Sum f1 and f2.
        System.out.print("Sum: ");
        System.out.println(f1 + f2);
  }
}

Output:

f1 Value: 32.454
f2 Value: 178.44
Sum: 210.894

 

Content Protection by DMCA.com
Please Share