* 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)
| 16043 | * @returns {Function} Returns the new round function. |
| 16044 | */ |
| 16045 | function createRound(methodName) { |
| 16046 | var func = Math[methodName]; |
| 16047 | return function(number, precision) { |
| 16048 | number = toNumber(number); |
| 16049 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); |
| 16050 | if (precision) { |
| 16051 | // Shift with exponential notation to avoid floating-point issues. |
| 16052 | // See [MDN](https://mdn.io/round#Examples) for more details. |
| 16053 | var pair = (toString(number) + 'e').split('e'), |
| 16054 | value = func(pair[0] + 'e' + (+pair[1] + precision)); |
| 16055 | |
| 16056 | pair = (toString(value) + 'e').split('e'); |
| 16057 | return +(pair[0] + 'e' + (+pair[1] - precision)); |
| 16058 | } |
| 16059 | return func(number); |
| 16060 | }; |
| 16061 | } |
| 16062 | |
| 16063 | /** |
| 16064 | * Creates a set object of `values`. |