/**
 * Creates a function like `round`.
 *
 * @private
 * @param {string} methodName The name of the `Math` method to use when rounding.
 * @returns {Function} Returns the new round function.
 */
function createRound(methodName: "ceil" | "floor" | "round"): (number: number, precision?: number) => number {
    const func = Math[methodName];
    return (number: number, precision: number = 0) => {
        precision = precision >= 0 ? Math.min(precision, 292) : Math.max(precision, -292);
        if (precision) {
            let pair = `${number}e`.split("e");
            const value = func(Number(`${pair[0]}e${+pair[1] + precision}`));

            pair = `${value}e`.split("e");
            return +`${pair[0]}e${+pair[1] - precision}`;
        }
        return func(number);
    };
}

export default createRound;
// /**
//  * Creates a function like `round`.
//  *
//  * @private
//  * @param {string} methodName The name of the `Math` method to use when rounding.
//  * @returns {Function} Returns the new round function.
//  */
// function createRound(methodName) {
//     const func = Math[methodName];
//     return (number, precision) => {
//         precision = precision == null ? 0 : precision >= 0 ? Math.min(precision, 292) : Math.max(precision, -292);
//         if (precision) {
//             // Shift with exponential notation to avoid floating-point issues.
//             // See [MDN](https://mdn.io/round#Examples) for more details.
//             let pair = `${number}e`.split("e");
//             const value = func(`${pair[0]}e${+pair[1] + precision}`);

//             pair = `${value}e`.split("e");
//             return +`${pair[0]}e${+pair[1] - precision}`;
//         }
//         return func(number);
//     };
// }

// export default createRound;
