* 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)
| 13065 | * @returns {Function} Returns the new round function. |
| 13066 | */ |
| 13067 | function createRound(methodName) { |
| 13068 | var func = Math[methodName]; |
| 13069 | return function(number, precision) { |
| 13070 | number = toNumber(number); |
| 13071 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); |
| 13072 | if (precision) { |
| 13073 | // Shift with exponential notation to avoid floating-point issues. |
| 13074 | // See [MDN](https://mdn.io/round#Examples) for more details. |
| 13075 | var pair = (toString(number) + 'e').split('e'), |
| 13076 | value = func(pair[0] + 'e' + (+pair[1] + precision)); |
| 13077 | |
| 13078 | pair = (toString(value) + 'e').split('e'); |
| 13079 | return +(pair[0] + 'e' + (+pair[1] - precision)); |
| 13080 | } |
| 13081 | return func(number); |
| 13082 | }; |
| 13083 | } |
| 13084 | |
| 13085 | /** |
| 13086 | * Creates a set object of `values`. |
no test coverage detected