The Math.fround()
function returns the nearest 32-bit single precision float representation of a Number.
var singleFloat = Math.fround(doubleFloat); // doubleFloat is a Number.
If the parameter is not a number type, it will be converted to a number or to NaN if it cannot be converted.
let a = Math.fround(1.5); // 1.5 console.log(a);// w ww . java2 s. c o m a = Math.fround(1.337); // 1.3370000123977661 console.log(a); a = Math.fround(2 ** 150); // Infinity console.log(a); a = Math.fround('abc'); // NaN console.log(a); a = Math.fround(NaN); // NaN console.log(a); console.log(Math.fround(0.4)); // 0.4000000059604645 console.log(Math.fround(0.5)); // 0.5 console.log(Math.fround(25.9)); // 25.899999618530273