JavaScript Math.fround() returns the nearest 32-bit single precision float representation of a number. JavaScript numbers are normally 64-bit double precision values; Math.fround() rounds a value as if it were stored as a 32-bit float.
Environment: Node.js v20.18.2. Each snippet is plain JavaScript; the line after it states the expected console output.
Math.fround Syntax
Math.fround(x)The return value is the nearest 32-bit single precision float value for x.
Method 1: Round to 32-bit Float Precision
console.log(Math.fround(1.337));
console.log(Math.fround(1.5));You should see 2 lines, in order: 1.3370000123977661, 1.5.
Some numbers cannot be represented exactly as 32-bit floats, so the rounded result may look slightly different.
Method 2: Compare Math.fround(0.1) with 0.1
console.log(Math.fround(0.1) === 0.1);You should see one line logging false.
0.1 as a normal JavaScript number and 0.1 rounded to 32-bit float precision are not exactly the same value.
Method 3: Handle NaN with Math.fround()
console.log(Math.fround(NaN));You should see one line logging NaN.
Common Questions About Math.fround
What does fround mean?
fround means float round. It rounds a JavaScript number to nearest 32-bit single precision float representation.
What is the purpose of Math.fround()?
It lets JavaScript code intentionally work with float32-like precision instead of the usual 64-bit double precision number behavior.
Is Math.fround the same as Math.round?
No. Math.round() rounds to an integer. Math.fround() rounds to 32-bit floating-point precision.
Summary
Math.fround() matches float32 spacing—useful for WebGL buffers and interop, not for currency rounding.
JavaScript Math.fround() returns the nearest 32-bit single precision float representation of a number. It is useful for float32-sensitive work such as graphics, binary data, and matching lower-precision numeric systems. It is not meant for ordinary decimal rounding.
