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

Use Emoji’s in Python

Did you know you can use Emoji's in Python? Learn how to!

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...

Please Install Theme Required & Recommended PLugins.