I’d like to display decimal places intelligently (i.e. without having to choose between lengthy decimal places or a ton of trailing zeroes) in JavaScript. This is my original list:
6
8
12.225252
Currently I’m using toFixed(1), and have output like this:
6.0
8.0
12.2
Is there a way I can get:
6
8
12.2
instead? Obviously I can write some custom code to do this, but is there anything in-built in JavaScript?
You can use
Math.round.Examples: