What is float in Java?

Learnwithshikha
2 min readMay 16, 2021

--

In java, Float is primitive data type having number with a decimal point. It contains number of fractional parts from 3.4e−038 to 3.4e+038. Note that you should end the value with an “f”.

There are two types of primitive floating point.

1.Float

The float data type requires 4 bytes means 32-bits for their storage. The number of digit after decimals point are know as precision are 7. The range of the precision lies between -3.4E38 to +3.4E38.

For Example:

public class Main {
public static void main(String[] args) {
float myNum = 2.89f;
System.out.println(myNum);
}
}

Output:

2.89

2.Double

When we need to work with large decimal numbers, we use Double floating data type. It use 8 bytes means 64-bits for their storage. Its digits precision are 15. The range of the precision lies between -1.7e308 to +1.7e308. Note that you should end the value with a “d”.

For example:

public class Main {
public static void main(String[] args) {
double myNum = 21.99d;
System.out.println(myNum);
}
}

Output:

21.99

For more information please click hear

https://learnwithshikha.com/how-to-find-multiples-of-a-float-value-in-java/

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Learnwithshikha
Learnwithshikha

Written by Learnwithshikha

Hi, This is Shikha from India. I’m working as front-end developer besides a blogger. Here is my website https://learnwithshikha.com/

No responses yet

Write a response