To limit the amount of number shown after a decimal place in JavaScript, we can use the toFixed
method.
For instance, we can write:
const x = 4.8855;
console.log(x.toFixed(2));
Then we round x
to 2 decimal places.
The number of decimal places is the argument for toFixed
.
Therefore, the console log should log 4.89.