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

remove-duplicate-elements-in-a-list-with-python
Remove duplicate elements in a list with Python

A simple and efficient way to remove duplicate elements from a list using...

reverse-string
How to reverse a string

A simple way of reversing a string in different languages.

Please Install Theme Required & Recommended PLugins.