* 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.
(methodName)
| 11986 | * @returns {Function} Returns the new round function. |
| 11987 | */ |
| 11988 | function createRound(methodName) { |
| 11989 | var func = Math[methodName]; |
| 11990 | return function(number, precision) { |
| 11991 | number = toNumber(number); |
| 11992 | precision = nativeMin(toInteger(precision), 292); |
| 11993 | if (precision) { |
| 11994 | // Shift with exponential notation to avoid floating-point issues. |
| 11995 | // See [MDN](https://mdn.io/round#Examples) for more details. |
| 11996 | var pair = (toString(number) + 'e').split('e'), |
| 11997 | value = func(pair[0] + 'e' + (+pair[1] + precision)); |
| 11998 | |
| 11999 | pair = (toString(value) + 'e').split('e'); |
| 12000 | return +(pair[0] + 'e' + (+pair[1] - precision)); |
| 12001 | } |
| 12002 | return func(number); |
| 12003 | }; |
| 12004 | } |
| 12005 | |
| 12006 | /** |
| 12007 | * Creates a set of `values`. |
no test coverage detected