Get to know MDN better
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.
A number.
The nearest 16-bit half precision float representation of doubleFloat.
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).
The number 1.5 can be precisely represented in the binary numeral system, and is identical in 16-bit and 64-bit:
However, the number 1.337 cannot be precisely represented in the binary numeral system, so it differs in 16-bit and 64-bit:
100000 is too big for a 16-bit float, so Infinity is returned:
| ECMAScript® 2027 Language Specification # sec-math.f16round |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.