1 var toInteger = require('./toInteger'),
2 toNumber = require('./toNumber'),
3 toString = require('./toString');
5 /* Built-in method references for those with the same name as other `lodash` methods. */
6 var nativeMin = Math.min;
9 * Creates a function like `_.round`.
12 * @param {string} methodName The name of the `Math` method to use when rounding.
13 * @returns {Function} Returns the new round function.
15 function createRound(methodName) {
16 var func = Math[methodName];
17 return function(number, precision) {
18 number = toNumber(number);
19 precision = nativeMin(toInteger(precision), 292);
21 // Shift with exponential notation to avoid floating-point issues.
22 // See [MDN](https://mdn.io/round#Examples) for more details.
23 var pair = (toString(number) + 'e').split('e'),
24 value = func(pair[0] + 'e' + (+pair[1] + precision));
26 pair = (toString(value) + 'e').split('e');
27 return +(pair[0] + 'e' + (+pair[1] - precision));
33 module.exports = createRound;