MCPcopy Create free account
hub / github.com/deployd/deployd / createRound

Function createRound

test-app/public/sinon.js:16045–16061  ·  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

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

Callers 1

sinon.jsFile · 0.85

Calls 3

toNumberFunction · 0.85
toIntegerFunction · 0.85
toStringFunction · 0.70

Tested by

no test coverage detected