JavaScript Math.fround() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

Math.fround(x) rounds a number to the nearest 32-bit (single-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.fround() like this. Start with this line.

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

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

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

Parameters

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

Return Value

Return ValueDescription
numberThe nearest 32-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 fit exactly in 32 bits. Others are rounded.

JavaScript
console.log(Math.fround(5));       // 5
console.log(Math.fround(5.5));     // 5.5
console.log(Math.fround(5.05));    // 5.050000190734863
console.log(Math.fround(1.337));   // 1.3370000123977661
Try It Yourself

How It Works

  1. Exact values. 5 and 5.5 are stored exactly.
  2. Rounded values. 5.05 is stored as 5.050000190734863.
  3. Extra digits. The extra digits show the 32-bit rounding.

Example 2 — Compare With a 64-bit Number

A value rounded to 32 bits is often not equal to the original.

JavaScript
console.log(0.1 === Math.fround(0.1));   // false
console.log(0.5 === Math.fround(0.5));   // true
console.log(Math.fround(0.1));           // 0.10000000149011612
Try It Yourself

How It Works

  1. 0.1. It cannot be stored exactly, so the two values differ.
  2. 0.5. It is a power of two, so it is exact in both.
  3. See the value. The 32-bit version of 0.1 is slightly bigger.

Example 3 — Match Float32Array

Math.fround() gives the same value you would read back from a Float32Array.

JavaScript
var arr = new Float32Array([0.1]);

console.log(arr[0]);                          // 0.10000000149011612
console.log(Math.fround(0.1));                // 0.10000000149011612
console.log(arr[0] === Math.fround(0.1));     // true
console.log(Math.fround(2 ** 150));           // Infinity
Try It Yourself

How It Works

  1. Store. A Float32Array keeps each value as a 32-bit float.
  2. Read. Reading arr[0] returns the rounded value.
  3. Match. Math.fround(0.1) is the same value.
  4. Overflow. A number too large for 32 bits becomes Infinity.

Browser & Runtime Support

Math.fround() is part of ES2015 and is Baseline Widely available in modern browsers and Node.js.

✓ Baseline · ES2015

Math.fround()

Supported in Chrome, Firefox, Safari, Edge, and Node.js for years. Safe for modern apps without a polyfill.

98% 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.fround Excellent

Bottom line: Use Math.fround() in new code. Only very old browsers, like Internet Explorer, lack it.

Frequently Asked Questions

Math.fround(x) rounds x to the nearest 32-bit single-precision float and returns it as a JavaScript number.
JavaScript numbers use 64 bits. 0.1 as a 32-bit float is a slightly different value: 0.10000000149011612.
Use it to match 32-bit float data, like values from a Float32Array, WebGL, or audio code.
It returns Infinity, because the number is too large for a 32-bit float.
It was added in ES2015 and works in all modern browsers and Node.js.

Next: hypot()

Learn how to find the square root of the sum of squares.

hypot() 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.

10 people found this page helpful