float keyword in java

In Java, float ” is a primitive type.

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:

1
2
3
4
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:

1
2
3
4
public float getMarks() {
 
                return 94.5f;
}
public float getMarks() {
 
                return 94.5f;
}

About the Author

Karibasappa G C (KB)
Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on