setFloat32() writes a number into four bytes of a DataView as a 32-bit floating point value (single precision). The number is rounded to about 7 significant digits, so it uses half the space of a normal JavaScript Number while staying accurate enough for most measurements. Pass the byte offset, the value and, for little-endian formats, true.
Converts value to a 32-bit floating point number (single precision) and writes it into the 4 bytes starting at byteOffset, big-endian. Returns undefined.
view.setFloat32(byteOffset, value, true)
Writes the same 4 bytes in little-endian order, so the least significant byte lands at byteOffset.
Part of the original DataView from ES2015, so every modern browser and runtime has it. Unlike a Float32Array, a DataView has no alignment rule: setFloat32() works at any byte position, even one that is not a multiple of 4.
Library declarations
JavaScript
DataView.prototype.setFloat32(byteOffset, value)
DataView.prototype.setFloat32(byteOffset, value, littleEndian)
// returns undefined; writes 4 bytes starting at byteOffset
// value is converted to a 32-bit floating point number
// needs byteOffset + 4 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian
Parameters
Parameter
Description
byteOffset
Where to start writing, 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 4 bytes must fit: byteOffset + 4 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
value
The number to store. It is rounded to the nearest 32-bit floating point number, so 0.1 comes back as 0.10000000149011612. Values beyond about ±3.4e38 become Infinity or -Infinity.
littleEndian
Optional. Leave it out (or pass false) for big-endian: the most significant of the 4 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
undefined
setFloat32() gives nothing back. Its result is the 4 bytes it changed inside the buffer; read them back with getFloat32().
JavaScript Examples
Example 1 — Save Temperatures in 4 and 8 Bytes
Write each temperature once with setFloat32() and once with setFloat64(), and compare what comes back.
Integers up to 16777216 are safe. A float32 has 24 bits of precision, so every whole number up to 2 to the power 24 (16777216) is exact.
The next integer is not. 16777217 cannot be stored, so setFloat32() rounds it to 16777216.
Huge values: rounded or Infinity. 3.4e38 is close to the maximum and is stored slightly rounded; 1e39 is beyond the float32 range and becomes Infinity.
Compatibility
Browser & Runtime Support
setFloat32() has been part of JavaScript since ES2015, when DataView itself was standardised.
✓ ES2015 · Baseline
DataView.prototype.setFloat32()
Works in every modern browser and in Node.js, Deno and Bun. It runs on a normal ArrayBuffer, so no special page setup is needed.
100%Modern browser support
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeModern versions · Chromium
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Internet ExplorerRetired browser · not tested here
Legacy
Node.jsCurrent releases · checked on Node 24
Supported
DenoCurrent releases
Supported
BunCurrent releases
Supported
setFloat32()All modern engines
Bottom line: Safe to use without a fallback. It also works on a SharedArrayBuffer, but a normal ArrayBuffer is all you need.
Frequently Asked Questions
It rounds a number to the nearest 32-bit float and writes those four bytes at the offset. It returns undefined.
A 32-bit float keeps about 7 digits. The stored value is the closest float32 to 21.7, and reading it as a 64-bit Number shows the tiny difference.
About 3.4028234663852886e38. Larger values are stored as Infinity.
When space matters and 7 digits are enough, for example large arrays of sensor readings, audio or 3D vertex data, or when a file format requires 4-byte floats.
It converts the value to a Number first, so "2.5" is stored as 2.5. A string that is not a number becomes NaN.