/** * The figure printed above a chart: whole numbers stay whole, a fraction * keeps at most two decimals, and the unit says what was counted. * * @param {number | string} total - The chart's total. * @param {string} unit - What the total counts, e.g. ``hits``; empty for none. * @returns {string} The figure, e.g. ``13 hits``. */ export const chartTotal = ( total: number | string, unit: string = '' ): string => { const figure = Number(total).toLocaleString('en-US', { maximumFractionDigits: 2, }); return unit ? `${figure} ${unit}` : figure; };