Как удалить конечные нули из числа в JavaScript

Регулярное выражение

const toFixedWithoutZeros = (num, precision) =>
  num.toFixed(precision).replace(/\.0+$/, '');

toFixedWithoutZeros(1.001, 2); // '1'
toFixedWithoutZeros(1.500, 2); // '1.50'

Умножить на 1

const toFixedWithoutZeros = (num, precision) =>
  `${1 * num.toFixed(precision)}`;

toFixedWithoutZeros(1.001, 2); // '1'
toFixedWithoutZeros(1.500, 2); // '1.5'

Число.parseFloat

const toFixedWithoutZeros = (num, precision) =>
  `${Number.parseFloat(num.toFixed(precision))}`;

toFixedWithoutZeros(1.001, 2); // '1'
toFixedWithoutZeros(1.500, 2); // '1.5'
Числа JavaScript