In the following example, we will simply round off 123.788975488 to 2 decimal places and display it on the screen. We are going to use the toFixed() method to achieve it easily. To access the toFixed() method, a variable should be of number type.
toFixed() method simply takes one optional parameter where you can specify the number of digits to appear after the decimal. In case, you do not pass any parameter, it will be treated as 0. Please have a look over the code example and steps given below.
HTML & CSS
We have 3 elements in the HTML file (div, button, and h1). The div element is just a wrapper for the rest of the elements.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.