I would like to round to two decimal places, only when necessary . Here are examples of inputs and outputs
Entry:
10
1.7777777
9.1
Departure:
10
1.78
9.1
How can I do this in JavaScript?
Fragment
var valor = [
10,
1.77777777,
9.1
];
var resultado = valor.map(Math.round);
console.log(resultado);
Question inspired by Round to at most 2 decimal places