DataView.prototype.setFloat32()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

setFloat32()DataView起始位置以 byte 为计数的指定偏移量 (byteOffset) 处储存一个 32-bit 数 (浮点型)。

尝试一下

// Create an ArrayBuffer with a size in bytes
const buffer = new ArrayBuffer(16);

const view = new DataView(buffer);
view.setFloat32(1, Math.PI);

console.log(view.getFloat32(1));
// Expected output: 3.1415927410125732

语法

dataview.setFloat32(byteOffset, value [, littleEndian])

参数

byteOffset

偏移量,从头开始计算,单位为字节。

value

设置的数值。

littleEndian

可选 Indicates whether the 32-bit float is stored in little- or big-endian format. If false or undefined, a big-endian value is written.

返回

抛出错误

RangeError

如果 byteOffset 超出了视图能储存的值,就会抛出错误。

示例

js
var buffer = new ArrayBuffer(8);
var dataview = new DataView(buffer);
dataview.setFloat32(1, 3);
dataview.getFloat32(1); // 3

规范

Specification
ECMAScript® 2025 Language Specification
# sec-dataview.prototype.setfloat32

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
setFloat32

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

相关内容