as described in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed saying:
The number is rounded if necessary, and if necessary, the fractional part is filled with zeros so that it has the specified length.
For -0.245.toFixed (2), the value is negative, and the value after 2 decimal places is 0.045, -0.045 is greater than -0.05, so the result is rounded to -0.24
For -9.085.toFixed (2), the value is negative, and the value after two decimal places is 0.085, -0.085 is less than -0.08, so the result is rounded to -9.09
Below is a solution for rounding to two decimal places for a negative value.
var num = -9.085 var output = num < 0 ? Math.floor(Math.abs(num) * 100) * -1 / 100 : num.toFixed(2) console.log(output)
alpha source share