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 theNumbertype for which we want to find thefround().
Numberin JavaScript is a 64-bit double-precision value that is the same asdoublein C# or Java.
Return value
-
Number: TheMath.fround()function returns the next nearest 32-bit floating point of the input parameterparam. It is of theNumbertype. -
NaN: TheMath.fround()function returns if the inputNaN Not a Number paramis not of theNumbertype.
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'));