The Wikipedia page on it is a good place to start.

To sum up:

  • float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the significand (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the significand).

  • double is represented in 64 bits, with 1 sign bit, 11 bits of exponent, and 52 bits of significand.

By default, Java uses double to represent its floating-point numerals (so a literal 3.14 is typed double). It's also the data type that will give you a much larger number range, so I would strongly encourage its use over float.

There may be certain libraries that actually force your usage of float, but in general - unless you can guarantee that your result will be small enough to fit in float's prescribed range, then it's best to opt with double.

If you require accuracy - for instance, you can't have a decimal value that is inaccurate (like 1/10 + 2/10), or you're doing anything with currency (for example, representing $10.33 in the system), then use a BigDecimal, which can support an arbitrary amount of precision and handle situations like that elegantly.

Answer from Makoto on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
The floating point types (float and double) can also be expressed using E or e (for scientific notation), F or f (32-bit float literal) and D or d (64-bit double literal; this is the default and by convention is omitted).
🌐
ZetCode
zetcode.com › java › float-types
Java Floating-Point Numbers - Complete Guide
Java offers two floating-point types: float (32-bit) and double (64-bit), both IEEE 754-based.
🌐
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 main difference between Java Float and Double is their precision and range. Float is a 32-bit floating-point number, which means that it can store up to 7 decimal digits accurately while Double is a 64-bit floating-point number, which means that it can store up to 15 decimal digits accurately.
🌐
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.
Published: May 23, 2026
🌐
Oracle
docs.oracle.com › en › java › javase › 24 › docs › api › java.base › java › lang › Float.html
Float (Java SE 24 & JDK 24)
July 15, 2025 - The IEEE 754 standard defines binary16 as a 16-bit format, along with the 32-bit binary32 format (corresponding to the float type) and the 64-bit binary64 format (corresponding to the double type). The binary16 format is similar to the other IEEE 754 formats, except smaller, having all the usual IEEE 754 values such as NaN, signed infinities, signed zeros, and subnormals.
🌐
Educative
educative.io › blog › float-vs-double-in-java
Float vs. double in Java
In Java, float is a 32-bit single-precision floating-point type and double is a 64-bit double-precision floating-point type, with double being the default for decimal literals.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-data-types
Java Data Types - GeeksforGeeks
A 64-bit double-precision floating-point type and the default for decimal numbers. ... Size : 8 bytes (64 bits). It is recommended to go through rounding off errors in java.
Published: September 30, 2026
Find elsewhere
🌐
Gloomba
gloomba.com › en › what-is-the-size-of-a-float-in-java-*-1-point-8-bits-16-bits-32-bits-64-bits
What is the Size of a Float in Java * 1 Point 8 Bits 16 Bits 32 Bits 64 Bits: A Comprehensive Deep Dive - gloomba
July 5, 2026 - To cut straight to the chase and ... standardized value across all Java Virtual Machine (JVM) implementations. You won't find variations like 16 bits or 64 bits for the primitive `float` type....
🌐
The Floating-Point Guide
floating-point-gui.de › languages › java
The Floating-Point Guide - Floating-point cheat sheet for Java
Java has IEEE 754 single and double precision types supported by keywords: float f = 0.1f; // 32 bit float, note f suffix double d = 0.1d; // 64 bit float, suffix optional
🌐
EDUCBA
educba.com › home › software development › software development tutorials › top differences tutorial › java float vs double
Java float vs Double | Top 7 Beneficial Comparisons To Learn
January 11, 2024 - The range of values is beyond this ... and Values section of the Java Language Specification. The double data type is a double-precision 64-bit IEEE 754 floating-point....
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Medium
silvahansini.medium.com › floating-point-representation-in-java-da50f603b599
Floating-Point Representation in Java | by Hasini Sandunika Silva | May, 2021 | Medium | Medium
May 17, 2021 - Figure 1. shows the IEEE-754 standard representation of float data type in Java. ... Figure 1. Standard-Single Precision Representation. double: This is represented by 64-bits (8-bytes) in memory (by two words in JVM).
🌐
Study.com
study.com › business courses › java programming tutorial & training
Java: Floating Point Numbers - Lesson | Study.com
October 3, 2018 - The single precision number format occupies 4 bytes, or 32 bits, in computer memory, while the double precision number format occupies 8 bytes, or 64 bits, in the memory of a computer.
🌐
Incus Data
incusdata.com › home › floating point numbers in java
Floating Point Numbers in Java • 2026 • Incus Data Programming Courses
July 30, 2024 - There are three basic binary floating-point formats (32, 64 or 128 bits) and two basic decimal floating-point formats (encoded with 64 or 128 bits). There are also a number of interchange formats. The Java floating point types conform to the IEEE 754 standard.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Float.html
Float (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... The Float class wraps a value of primitive type float in an object.
🌐
Oracle
docs.oracle.com › en › java › javase › 22 › docs › api › java.base › java › lang › Float.html
Float (Java SE 22 & JDK 22)
July 16, 2024 - The IEEE 754 standard defines binary16 as a 16-bit format, along with the 32-bit binary32 format (corresponding to the float type) and the 64-bit binary64 format (corresponding to the double type). The binary16 format is similar to the other IEEE 754 formats, except smaller, having all the usual IEEE 754 values such as NaN, signed infinities, signed zeros, and subnormals.
Top answer
1 of 1
12

The first thing to realize is that the binary representation of 0.15625 is not 0.00101. Yes, that is what you would write if you were writing out the number by hand. The actual representation of the number within the computer using IEE 754 for single precision 32 bit. This is specified as part of the Java Language Specification 4.2:

The floating-point types are float, whose values include the 32-bit IEEE 754 floating-point numbers, and double, whose values include the 64-bit IEEE 754 floating-point numbers.

The IEEE 754 binary representation of 0.15625 is: 0x3E200000 which can be broken down into:

  • a sign bit: 0 meaning it is positive.
  • the exponent for bits: 01111100 which is 124. This value is subtracted from 127 to get the actual exponent that will be used (-3)
  • the significand: .0100000 00000000 00000000. The . I put there is for reading so that it is bytes, not part of the value (the significant uses the lower 23 bits of the number... so the 24th bit I represent with a . so the alignment is easier to read) This value is added to 1 giving us the binary value of 1.010.... or in base 10, 1.25000...

Combining these all together, we get:

(-1)0 * 1.012 * 2-3 which comes out to be, when written, 0.00101. But remember, that we're really dealing with 0x3E200000.


Lets take a quick Java source file:

package com.michaelt.so.floating;

public class Demo {
    float foo = 0.15625f;
}

The byte code for this, when decompiled is:

// class version 50.0 (50)
// access flags 0x21
public class com/michaelt/so/floating/Demo {

  // compiled from: Demo.java

  // access flags 0x0
  F foo

  // access flags 0x1
  public <init>()V
   L0
    LINENUMBER 3 L0
    ALOAD 0
    INVOKESPECIAL java/lang/Object.<init> ()V
   L1
    LINENUMBER 4 L1
    ALOAD 0
    LDC 0.15625
    PUTFIELD com/michaelt/so/floating/Demo.foo : F
    RETURN
   L2
    LOCALVARIABLE this Lcom/michaelt/so/floating/Demo; L0 L2 0
    MAXSTACK = 2
    MAXLOCALS = 1
}

Which really isn't too interesting. You can see the LDC 0.15625 in there which is a load constant opcode. It takes one argument from a constant pool and pushes it on the stack.

So, lets look at Demo.class with a hex dump viewer.

$ hexdump -C Demo.class 
00000000  ca fe ba be 00 00 00 32  00 15 0a 00 05 00 11 04  |.......2........|
00000010  3e 20 00 00 09 00 04 00  12 07 00 13 07 00 14 01  |> ..............|
00000020  00 03 66 6f 6f 01 00 01  46 01 00 06 3c 69 6e 69  |..foo...F...<ini|
00000030  74 3e 01 00 03 28 29 56  01 00 04 43 6f 64 65 01  |t>...()V...Code.|
00000040  00 0f 4c 69 6e 65 4e 75  6d 62 65 72 54 61 62 6c  |..LineNumberTabl|
00000050  65 01 00 12 4c 6f 63 61  6c 56 61 72 69 61 62 6c  |e...LocalVariabl|
00000060  65 54 61 62 6c 65 01 00  04 74 68 69 73 01 00 1f  |eTable...this...|
00000070  4c 63 6f 6d 2f 6d 69 63  68 61 65 6c 74 2f 73 6f  |Lcom/michaelt/so|
00000080  2f 66 6c 6f 61 74 69 6e  67 2f 44 65 6d 6f 3b 01  |/floating/Demo;.|
00000090  00 0a 53 6f 75 72 63 65  46 69 6c 65 01 00 09 44  |..SourceFile...D|
000000a0  65 6d 6f 2e 6a 61 76 61  0c 00 08 00 09 0c 00 06  |emo.java........|
000000b0  00 07 01 00 1d 63 6f 6d  2f 6d 69 63 68 61 65 6c  |.....com/michael|
000000c0  74 2f 73 6f 2f 66 6c 6f  61 74 69 6e 67 2f 44 65  |t/so/floating/De|
000000d0  6d 6f 01 00 10 6a 61 76  61 2f 6c 61 6e 67 2f 4f  |mo...java/lang/O|
000000e0  62 6a 65 63 74 00 21 00  04 00 05 00 00 00 01 00  |bject.!.........|
000000f0  00 00 06 00 07 00 00 00  01 00 01 00 08 00 09 00  |................|
00000100  01 00 0a 00 00 00 39 00  02 00 01 00 00 00 0b 2a  |......9........*|
00000110  b7 00 01 2a 12 02 b5 00  03 b1 00 00 00 02 00 0b  |...*............|
00000120  00 00 00 0a 00 02 00 00  00 03 00 04 00 04 00 0c  |................|
00000130  00 00 00 0c 00 01 00 00  00 0b 00 0d 00 0e 00 00  |................|
00000140  00 01 00 0f 00 00 00 02  00 10                    |..........|
0000014a

Look, right there at the start of the second line...

00000010  3e 20 00 00

There's the number.


Someone is going to ask 'but why is the number way up there? There's not even a 12 near it (the hex value for LDC).' And they are right to ask this. Remember that the LDC tool a value from the constant pool. The byte code that I had earlier was converted back into something a person could read.

The structure of a class file can be found in the Java Virtual Machine Specification section 4.1:

ClassFile {
    u4             magic;
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        constant_pool[constant_pool_count-1];
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}

We've got the magic number at the top (ca fe ba be), and the minor version (00 00), and major version (00 32 = 5010) and then the constant pool count (00 15) which then has the constant pool itself.

The constant pool is specified in section 4.4 which has the format:

cp_info {
    u1 tag;
    u1 info[];
}

The tag value of 04 says that 'what is next is a float`. You can see it at the end of the preceding line.

00000000  ca fe ba be 00 00 00 32  00 15 0a 00 05 00 11 04  |.......2........|
00000010  3e 20 00 00 09 00 04 00  12 07 00 13 07 00 14 01  |> ..............|

The other stuff that is around the number is information about locations for methods (it still has a default constructor), the name of the field, the name of the class, etc... there are a bunch of constants in there.

The key thing there though, you can see the floating point number stored in the class file as an IEEE 754 value that indicates this is something that the compiler does.

🌐
Wikipedia
en.wikipedia.org › wiki › Double-precision_floating-point_format
Double-precision floating-point format - Wikipedia
1 month ago - Double-precision floating-point format (sometimes called FP64 or float64) is a floating-point number format, usually occupying 64 bits in computer memory; it represents a wide range of numeric values by using a floating radix point.
🌐
KooR
koor.fr › Java › Tutorial › java_types_flottants.wp
KooR.fr - Manipulation des types flottants - Le tutoriel sur le langage de programmation Java
Le type double permet, qu'en à lui, la manipulation de flottants en double précision : du coup,les variables basées sur ce type occuperont le double d'espace en mémoire, soit 8 octets (64 bits).
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-illustrate-the-usage-of-floating
Java Program to Illustrate the Usage of Floating - GeeksforGeeks
September 7, 2021 - The default value in java is 0.0f and its size is 4 bytes. Float in java can have negative values.