MCPcopy
hub / github.com/Kong/insomnia / createRound

Function createRound

packages/insomnia/bin/yarn-standalone.js:13067–13083  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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`.

Callers 1

yarn-standalone.jsFile · 0.85

Calls 4

toNumberFunction · 0.85
toIntegerFunction · 0.85
toStringFunction · 0.85
funcFunction · 0.85

Tested by

no test coverage detected