display 2 decimal places javascript

Display a number to 2 decimal places in JavaScript

Display a number to 2 decimal places in JavaScript

In JavaScript you can easily display a number to a fixed amount of digits. All you need to do is pass in the number into the toFixed JavaScript method.

JavaScript Code

const a = 100/6;
const b = (100/6).toFixed(2);

console.log({a,b});


/* //OUTPUT
{
  a: 16.666666666666668
  b: "16.67"
}
*/

Related Posts

detect if page is active in javascript
Detect if page is active in JavaScript

You can use the Page Visibility API to do certain things when a...

reverse-string
How to reverse a string

A simple way of reversing a string in different languages.

Please Install Theme Required & Recommended PLugins.