float keyword in java
In Java, ”
” is a primitive type.float
A float variable stores a double−precision 32-bit floating point value.
Examples
float ratio = .01f
;
float diameter = 6.15f
;
The float
keyword can be used as a method parameter as below:
- public void displayMarks(float marks) {
- System.out.println("Total percentage marks "+marks);
- }
public void displayMarks(float marks) { System.out.println("Total percentage marks "+marks); }
The float
keyword can be used as a return type of a method as well:
- public float getMarks() {
- return 94.5f;
- }
public float getMarks() { return 94.5f; }