🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; // Floating point number char myLetter = 'D'; // Character boolean myBool = true; // Boolean String myText = "Hello"; // String
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
The signed long has a minimum value ... etc to support arithmetic operations for unsigned long. float: The float data type is a single-precision 32-bit IEEE 754 floating point....
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
The key difference between a float and double in Java is that a double can represent much larger numbers than a float. Both data types represent numbers with decimals, but a float is 32 bits in size while a double is 64 bits.
🌐
Quora
quora.com › How-many-bytes-is-a-float-in-Java
How many bytes is a float in Java? - Quora
Answer: Hi! float data type size is 4 bytes! The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. You should use a floating data type whenever you need a number with a decimal, such as 3.99 or 9.6715.
🌐
IBM
ibm.com › docs › en › i › 7.4.0
COBOL and Java Data Types
We cannot provide a description for this page right now
🌐
Baeldung
baeldung.com › home › java › java numbers › float vs. double in java
Float vs. Double in Java | Baeldung
January 4, 2025 - A float is a 32-bit single-precision floating-point type, occupying four bytes of memory. This compact size makes it well-suited for memory-constrained environments like embedded systems and mobile devices.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
October 20, 2025 - If the argument is any value in the range 0x7f800001 through 0x7fffffff or in the range 0xff800001 through 0xffffffff, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › float vs double in java - difference you should know
Float Vs Double in Java - Difference You Should Know - Scaler Topics
March 27, 2024 - The float keyword in Java is a primitive data type, and its size limit is 4 byte or 32 bits (1 byte = 8 bits) single-precision IEEE 754 (Standard for Floating-Point Arithmetic) floating-point number, that is it can allow up to 6 digits precision ...
🌐
CS Fundamentals
cs-fundamentals.com › tech-interview › java › how-to-find-size-of-a-datatype-in-java
Find Size of Primitive Data Type in Java
Size of short: 2 bytes. Size of int: 4 bytes. Size of long: 8 bytes. Size of char: 2 bytes. Size of float: 4 bytes. Size of double: 8 bytes. Note that size of primitive types in Java is always the same.
🌐
iO Flood
ioflood.com › blog › java-float
Java Float Keyword Explained: Usage and Examples
February 26, 2024 - It’s designed to hold decimal ... of float. ... Is a single-precision 32-bit IEEE 754 floating point. Has a size of 4 bytes....
🌐
GeeksforGeeks
geeksforgeeks.org › data-types-in-java
Java Data Types | GeeksforGeeks
Use a float (instead of double) if you need to save memory in large arrays of floating-point numbers. The size of the float data type is 4 bytes (32 bits).
Published   April 7, 2025
🌐
Medium
tarunjain07.medium.com › java-datatypes-notes-8e70959f4898
float datatypes in Java— [Notes]. **WIP | by Tarun Jain | Medium
September 5, 2022 - Because floats and doubles cannot accurately represent the base 10 multiples that we use for money. This issue isn’t just for Java, it’s for any programming language that uses base 2 floating-point types. In base 10, you can write 10.25 as 1025 * 10–2 (an integer times a power of 10).
🌐
W3Schools
w3schools.com › java › ref_keyword_float.asp
Java float Keyword
Java Examples Java Videos Java ... ... The float keyword is a data type that can store fractional numbers from 3.4e−038 to 3.4e+038....
🌐
DataCamp
datacamp.com › doc › java › float
float Keyword in Java: Usage & Examples
The float data type is commonly used in situations where you need to save memory and the precision of the floating point number is not critical. ... value: The value to assign to the variable, which must be a floating point number suffixed with an f or F. public class FloatExample { public static void main(String[] args) { float pi = 3.14f; float gravity = 9.8F; System.out.println("Value of pi: " + pi); System.out.println("Value of gravity: " + gravity); } }
Top answer
1 of 3
118
  • float stores floating-point values, that is, values that have potential decimal places
  • int only stores integral values, that is, whole numbers

So while both are 32 bits wide, their use (and representation) is quite different. You cannot store 3.141 in an integer, but you can in a float.

Dissecting them both a little further:

In an integer, all bits except the leftmost one are used to store the number value. This is (in Java and many computers too) done in the so-called two's complement, which support negatives values. Two's complement uses the leftmost bit to store the positive (0) or negative sign (1). This basically means that you can represent the values of −231 to 231 − 1.

In a float, those 32 bits are divided between three distinct parts: The sign bit, the exponent and the mantissa. They are laid out as follows:

S EEEEEEEE MMMMMMMMMMMMMMMMMMMMMMM

There is a single bit that determines whether the number is negative or non-negative (zero is neither positive nor negative, but has the sign bit set to zero). Then there are eight bits of an exponent and 23 bits of mantissa. To get a useful number from that, (roughly) the following calculation is performed:

M × 2E

(There is more to it, but this should suffice for the purpose of this discussion)

The mantissa is in essence not much more than a 24-bit integer number. This gets multiplied by 2 to the power of the exponent part, which, roughly, is a number between −128 and 127.

Therefore you can accurately represent all numbers that would fit in a 24-bit integer but the numeric range is also much greater as larger exponents allow for larger values. For example, the maximum value for a float is around 3.4 × 1038 whereas int only allows values up to 2.1 × 109.

But that also means, since 32 bits only have 4.2 × 109 different states (which are all used to represent the values int can store), that at the larger end of float's numeric range the numbers are spaced wider apart (since there cannot be more unique float numbers than there are unique int numbers). You cannot represent some numbers exactly, then. For example, the number 2 × 1012 has a representation in float of 1,999,999,991,808. That might be close to 2,000,000,000,000 but it's not exact. Likewise, adding 1 to that number does not change it because 1 is too small to make a difference in the larger scales float is using there.

Similarly, you can also represent very small numbers (between 0 and 1) in a float but regardless of whether the numbers are very large or very small, float only has a precision of around 6 or 7 decimal digits. If you have large numbers those digits are at the start of the number (e.g. 4.51534 × 1035, which is nothing more than 451534 follows by 30 zeroes – and float cannot tell anything useful about whether those 30 digits are actually zeroes or something else), for very small numbers (e.g. 3.14159 × 10−27) they are at the far end of the number, way beyond the starting digits of 0.0000...

2 of 3
3

Floats are used to store a wider range of number than can be fit in an integer. These include decimal numbers and scientific notation style numbers that can be bigger values than can fit in 32 bits. Here's the deep dive into them: http://en.wikipedia.org/wiki/Floating_point