// rounds to the number of most significant digits, thus it takes into account the magnitude of the input number export const roundTo = (value: number, significantDigits: number) => { if (Math.abs(value) < 0.00001) return 0; const magnitudeDigits = Math.floor(Math.log10(Math.abs(value))); const scale = Math.pow( 10, Math.max(significantDigits - 1, 0) - magnitudeDigits ); return Math.round(value * scale) / scale; };