getFloat16() reads two bytes from a DataView and returns them as a 16-bit floating point number, also called half precision. A floating point number is a number with a decimal point that can “float”, so it can be tiny or large; with only 16 bits it keeps about 3 significant digits and reaches at most 65504. Graphics cards and machine-learning models use this format to save memory. It is one of the newest DataView methods (ES2025), so feature-detect it first.
Reads the 2 bytes starting at byteOffset in big-endian order (most significant byte first) and returns a 16-bit floating point number (half precision).
view.getFloat16(byteOffset, true)
Reads the same 2 bytes in little-endian order (least significant byte first), the order used by most file formats from PCs, such as WAV and BMP.
One of the newest DataView methods (ES2025, together with Float16Array and Math.f16round()). Node.js 24 has it; older browsers do not, so feature-detect it with typeof DataView.prototype.getFloat16 === "function". Unlike a Float16Array, a DataView has no alignment rule: getFloat16() works at any byte position, even one that is not a multiple of 2.
Library declarations
JavaScript
DataView.prototype.getFloat16(byteOffset)
DataView.prototype.getFloat16(byteOffset, littleEndian)
// returns a Number: about -65504 to 65504, about 3 significant digits
// reads 2 bytes starting at byteOffset (counted from the start of the view)
// needs byteOffset + 2 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian
Parameters
Parameter
Description
byteOffset
Where to start reading, counted in bytes from the start of the view (not of the underlying buffer). It is converted to a whole number, so 1.9 means 1 and "2" means 2. All 2 bytes must fit: byteOffset + 2 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
littleEndian
Optional. Leave it out (or pass false) for big-endian: the most significant of the 2 bytes comes first. Pass true for little-endian: the least significant byte comes first. Any truthy value, such as 1, also means little-endian.
Return Value
Return Value
Description
Number
The 2 bytes decoded as a 16-bit floating point number (half precision) and turned into a normal JavaScript Number (range about -65504 to 65504, about 3 significant digits). It can also be NaN, Infinity, -Infinity or -0.
JavaScript Examples
Example 1 — Read Machine-Learning Weights Stored as Half Floats
Neural networks store millions of weights, often as 2-byte floats. Put four known half-float bit patterns in a buffer and decode them.
JavaScript
const weights = new DataView(new ArrayBuffer(8));
weights.setUint16(0, 0x3c00); // bit pattern of 1
weights.setUint16(2, 0xc000); // -2
weights.setUint16(4, 0x3800); // 0.5
weights.setUint16(6, 0x3555); // about one third
for (let i = 0; i < weights.byteLength; i += 2) {
console.log("weight " + i / 2 + ": " + weights.getFloat16(i));
}
The Try It page first checks typeof DataView.prototype.getFloat16 === "function" (and the same for setFloat16). If your browser does not have them yet, it says so and shows the output above.
How It Works
Half-size numbers for a model. Using 2 bytes per weight instead of 4 or 8 lets a big model fit into much less memory.
Write raw bit patterns.setUint16() places known 16-bit float patterns in the buffer: 0x3c00 is 1, 0xc000 is -2 and 0x3800 is 0.5.
Decode each weight.getFloat16(i) turns every 2-byte pattern into a normal JavaScript Number. The last one shows that one third can only be stored roughly.
Example 2 — Round Trip Through Two Bytes
Write a few numbers as half floats and read them back to see exactly what 16 bits can keep.
The Try It page first checks typeof DataView.prototype.getFloat16 === "function" (and the same for setFloat16). If your browser does not have them yet, it says so and shows the output above.
How It Works
Write, then read back. Each number goes through setFloat16() and getFloat16(), so the output shows what survives.
About three digits survive. 0.1 becomes 0.0999755859375 and 3.14159 becomes 3.140625: close, but not exact.
Bigger numbers get coarser. The gaps between storable values grow with size: below 1024 they are 0.5 apart and above 2048 they are 2 apart, so 1000.7 becomes 1000.5 and 2049 becomes 2048.
Example 3 — Special Half-Float Bit Patterns
Some 16-bit patterns have special meanings. Decode the largest finite value, both infinities and NaN.
The Try It page first checks typeof DataView.prototype.getFloat16 === "function" (and the same for setFloat16). If your browser does not have them yet, it says so and shows the output above.
How It Works
The largest finite value. The pattern 7b ff is the biggest normal half-precision number, 65504.
Infinity has its own pattern. All exponent bits on with a zero fraction (7c 00) means Infinity; with the sign bit as well (fc 00) it is -Infinity.
Not a number. Exponent bits on with a non-zero fraction (7e 00) decodes to NaN.
Compatibility
Browser & Runtime Support
getFloat16() is one of the newest JavaScript features (ES2025, the Float16 proposal). Engines added it only recently.
✓ ES2025 · feature-detect
DataView.prototype.getFloat16()
Checked in Node.js 24. In browsers it is limited to the newest versions, so test for it with typeof before calling it.
NewSupport is still growing
Google ChromeNewest versions only
Check version
Mozilla FirefoxNewest versions only
Check version
Apple SafariNewest versions only
Check version
Microsoft EdgeNewest versions only
Check version
OperaNewest versions only
Check version
Samsung InternetNewest versions only
Check version
Internet ExplorerNo Float16 support
Not supported
Node.jsAvailable in Node 24 (checked)
Supported
DenoRecent releases
Check version
BunRecent releases
Check version
getFloat16()Newest engines only
Bottom line: Guard it: if (typeof DataView.prototype.getFloat16 === "function") { ... }. Without it, store the value with getFloat32() instead, which costs 4 bytes instead of 2.
Frequently Asked Questions
A method that reads two bytes as a 16-bit (half precision) floating point number and returns it as a normal JavaScript Number.
Not yet. It was added in ES2025, so only the newest browser versions have it. Node.js 24 supports it. Check typeof DataView.prototype.getFloat16 === "function" first.
About 3 significant decimal digits. 0.1 reads back as 0.0999755859375, and above 2048 only even whole numbers can be stored.
65504, apart from Infinity. Larger values cannot be stored in a 16-bit float.
When the data was saved as half floats, for example GPU textures or compressed machine-learning weights. For general numbers getFloat32() or getFloat64() are more precise.