Как удалить конечные нули из числа в JavaScript Регулярное выражение const toFixedWithoutZeros = (num, precision) => num.toFixed(precision).replace(/\.0+$/, ''); toFixedWithoutZeros(1.001, 2); // '1' toFixedWithoutZeros(1.500, 2); // '1.50'JavaScriptCopy Умножить на 1 const toFixedWithoutZeros = (num, precision) => `${1 * num.toFixed(precision)}`; toFixedWithoutZeros(1.001, 2); // '1' toFixedWithoutZeros(1.500, 2); // '1.5'JavaScriptCopy Число.parseFloat const toFixedWithoutZeros = (num, precision) => `${Number.parseFloat(num.toFixed(precision))}`; toFixedWithoutZeros(1.001, 2); // '1' toFixedWithoutZeros(1.500, 2); // '1.5'JavaScriptCopy Числа JavaScript