The solution to the problem of imprecision in toFixed

found a lot of methods on the Internet, all of which did not take into account the negative number. It was found that the negative number did not add 1, and the reliable toFixed rewriting method was found

.
Number.prototype.toFixed=function(s) {//toFixed
  return (parseInt(this * Math.pow( 10, s ) + 0.5)/ Math.pow( 10, s )).toString();
}

let num = -2999033.45645;
num.toFixed(4);
//-2999033.4564 1
Mar.10,2022

Number.prototype.toFixed=function(s) {//toFixed
  const adjust = this >= 0 ? 0.5 : -0.5;
  return (parseInt(this * Math.pow( 10, s ) + adjust)/ Math.pow( 10, s )).toString();
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9ed57-1a0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9ed57-1a0c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?