Math.f16round()

Baseline 2025
Newly available

Since April 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The Math.f16round() static method returns the nearest 16-bit half precision float representation of a number.

Try it

console.log(Math.f16round(5.5));
// Expected output: 5.5

console.log(Math.f16round(5.05));
// Expected output: 5.05078125

console.log(Math.f16round(5));
// Expected output: 5

console.log(Math.f16round(-5.05));
// Expected output: -5.05078125

Syntax

js
Math.f16round(doubleFloat)

Parameters

doubleFloat

A number.

Return value

The nearest 16-bit half precision float representation of doubleFloat.

Description

Math.f16round is the 16-bit counterpart of Math.fround(). It is intended to smooth some rough edges when interacting with float16 numbers, such as when reading from a Float16Array. Internally, JavaScript continues to treat the number as a 64-bit float, it just performs a "round to even" on the 10th bit of the mantissa, and sets all following mantissa bits to 0. If the number is outside the range of a 16-bit float, Infinity or -Infinity is returned.

Because f16round() is a static method of Math, you always use it as Math.f16round(), rather than as a method of a Math object you created (Math is not a constructor).

Examples

Using Math.f16round()

The number 1.5 can be precisely represented in the binary numeral system, and is identical in 16-bit and 64-bit:

js
Math.f16round(1.5); // 1.5
Math.f16round(1.5) === 1.5; // true

However, the number 1.337 cannot be precisely represented in the binary numeral system, so it differs in 16-bit and 64-bit:

js
Math.f16round(1.337); // 1.3369140625
Math.f16round(1.337) === 1.337; // false

100000 is too big for a 16-bit float, so Infinity is returned:

js
Math.f16round(100000); // Infinity

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-math.f16round

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
f16round
Chrome – Full support
Chrome 135 (Release date: 2025-04-01)
footnote Full support
Edge – Full support
Edge 135 (Release date: 2025-04-04)
footnote Full support
Firefox – Full support
Firefox 129 (Release date: 2024-08-06)
footnote Full support
Opera – Full support
Opera 120 (Release date: 2025-07-02)
footnote Full support
Safari – Full support
Safari 18.2 (Release date: 2024-12-11)
footnote Full support
Chrome Android – Full support
Chrome Android 135 (Release date: 2025-04-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 129 (Release date: 2024-08-06)
footnote Full support
Opera Android – Full support
Opera Android 89 (Release date: 2025-04-29)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 135 (Release date: 2025-04-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Bun – Full support
Bun 1.1.23 (Release date: 2024-08-14)
footnote Full support
Deno – Full support
Deno 1.43 (Release date: 2024-05-01)
footnote Full support
Node.js – Full support
Node.js 24 (Release date: 2025-05-06)
footnote Full support

Legend

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

Full support
Full support

See also