basant307/AI_Governance_Project
045
1import root from './_root.js';2import toInteger from './toInteger.js';3import toNumber from './toNumber.js';4import toString from './toString.js';5 6/* Built-in method references for those with the same name as other `lodash` methods. */7var nativeIsFinite = root.isFinite,8 nativeMin = Math.min;9 10/**11 * Creates a function like `_.round`.12 *13 * @private14 * @param {string} methodName The name of the `Math` method to use when rounding.15 * @returns {Function} Returns the new round function.16 */17function createRound(methodName) {18 var func = Math[methodName];19 return function(number, precision) {20 number = toNumber(number);21 precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);22 if (precision && nativeIsFinite(number)) {23 // Shift with exponential notation to avoid floating-point issues.24 // See [MDN](https://mdn.io/round#Examples) for more details.25 var pair = (toString(number) + 'e').split('e'),26 value = func(pair[0] + 'e' + (+pair[1] + precision));27 28 pair = (toString(value) + 'e').split('e');29 return +(pair[0] + 'e' + (+pair[1] - precision));30 }31 return func(number);32 };33}34 35export default createRound;36 