Convert a number to a string with a fixed number of decimal places without trailing zeros
Convert a number to a string with a fixed number of decimal places without trailing zeros
Section titled “Convert a number to a string with a fixed number of decimal places without trailing zeros”/** * This function converts a number to a string with a specified number of decimals, * and removes trailing zeros after the decimal point. * * @param num - The number to format. * @param precision - The number of decimal places. * @returns The formatted number as a string. * * @example * toFixedWithoutZeros(1.23000, 5) * // returns "1.23" * * @example * toFixedWithoutZeros(1.50000, 5) * // returns "1.5" * * @example * toFixedWithoutZeros(1.00000, 5) * // returns "1" */export const toFixedWithoutZeros = (num: number, precision: number): string => `${Number.parseFloat(num.toFixed(precision))}`