Categories
JavaScript Answers

How to Limit the Amount of Number Shown After a Decimal Place in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *