What is Math.fround() in JavaScript?

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations.

We use the Math.fround() function to compute to the nearest 32-bit single-precision floating-point number.

Syntax

Math.fround(param);

Parameter

  • param: This is the input value of the Number type for which we want to find the fround().

Number in JavaScript is a 64-bit double-precision value that is the same as double in C# or Java.

Return value

  • Number: The Math.fround() function returns the next nearest 32-bit floating point of the input parameter param. It is of the Number type.

  • NaN: The Math.fround() function returns NaNNot a Number if the input param is not of the Number type.

Code

console.log("fround(-1.23) = " + Math.fround(-1.23));
console.log("fround(0.54) = " + Math.fround(0.54));
console.log("fround(1.23) = " + Math.fround(1.23));
console.log("fround('1.23') = " + Math.fround('1.23'));
console.log("fround('educative') = " + Math.fround('educative'));

Free Resources