JavaScript Math.f16round() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

Math.f16round(x) rounds a number to the nearest 16-bit (half-precision) floating-point value. It returns that value as a normal JavaScript number.

Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().

Syntax

Call Math.f16round() like this. Start with this line.

JavaScript
Math.f16round(x)
CallWhat it does
Math.f16round(x)Returns x rounded to the nearest 16-bit float.

Built into JavaScript. Call Math.f16round() on the Math object — no import required.

Library declarations
JavaScript
Math.f16round(x)
JavaScript
interface Math {
  f16round(x: number): number;
}

Parameters

ParameterDescription
xRequired. A number. Other values are converted to a number first.

Return Value

Return ValueDescription
numberThe nearest 16-bit float to x, as a number. Returns Infinity if x is too large, and NaN if x is not a number.

JavaScript Examples

Example 1 — Basic Use

Some numbers are stored exactly. Others are rounded.

JavaScript
console.log(Math.f16round(5));       // 5
console.log(Math.f16round(5.5));     // 5.5
console.log(Math.f16round(5.05));    // 5.05078125
console.log(Math.f16round(0.1));     // 0.0999755859375
Try It Yourself

How It Works

  1. Exact values. 5 and 5.5 fit exactly in 16 bits, so they do not change.
  2. Rounded values. 5.05 becomes 5.05078125, the closest 16-bit float.
  3. Fractions. 0.1 cannot be stored exactly, so you see a small difference.

Example 2 — Compare With Math.fround()

A 16-bit float is less precise than a 32-bit float.

JavaScript
var value = 1.337;

console.log(value);                   // 1.337
console.log(Math.fround(value));      // 1.3370000123977661
console.log(Math.f16round(value));    // 1.3369140625
Try It Yourself

How It Works

  1. Original. 1.337 is a normal 64-bit number.
  2. 32-bit. Math.fround keeps about 7 correct digits.
  3. 16-bit. Math.f16round keeps only about 3, so it drifts further.

Example 3 — Limits and Precision Loss

Big integers lose detail and huge numbers overflow.

JavaScript
console.log(Math.f16round(65504));   // 65504
console.log(Math.f16round(70000));   // Infinity
console.log(Math.f16round(2049));    // 2048
console.log(Math.f16round(2051));    // 2052
Try It Yourself

How It Works

  1. Largest value. 65504 is the biggest finite 16-bit float.
  2. Overflow. 70000 is too big, so you get Infinity.
  3. Gaps. Above 2048 only even integers fit, so 2049 rounds to 2048 and 2051 rounds to 2052.

Browser & Runtime Support

Math.f16round() is part of ES2025. It is Baseline Newly available in current browsers and Node.js 24+.

✓ Baseline · ES2025 · Newly available

Math.f16round()

Works in current Chrome, Edge, Firefox, Safari and Node.js 24+. Older browsers and runtimes may not have it, so check support first.

90% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Math.f16round Good

Bottom line: Use if (typeof Math.f16round === "function") before you call it if you must support older browsers.

Frequently Asked Questions

Math.f16round(x) rounds x to the nearest 16-bit half-precision float and returns it as a JavaScript number.
The largest finite 16-bit float is 65504. Math.f16round(70000) returns Infinity.
Math.fround() rounds to a 32-bit float (about 7 digits). Math.f16round() rounds to a 16-bit float (about 3 digits), so it loses more detail.
Use it to see how a value will look after being stored in a Float16Array, or when working with graphics and machine learning data.
It is a newer feature (ES2025). It works in current versions of Chrome, Edge, Firefox, Safari and Node.js 24+. Check support before using it in older environments.

Next: floor()

Learn how to round a number down to a whole number.

floor() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful