MCPcopy
hub / github.com/Jasonette/JASONETTE-iOS / createRound

Function createRound

app/Jasonette/csv.js:11988–12004  ·  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

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

Callers 1

runInContextFunction · 0.70

Calls 4

toNumberFunction · 0.70
toIntegerFunction · 0.70
toStringFunction · 0.70
funcFunction · 0.70

Tested by

no test coverage detected