Sha256: 09b84d1712b210ec6408eebb5d2f3a72f728c5e9ce7c9f86f621ad81a5d02bd1

Contents?: true

Size: 1.17 KB

Versions: 170

Compression:

Stored size: 1.17 KB

Contents

var root = require('./_root'),
    toInteger = require('./toInteger'),
    toNumber = require('./toNumber'),
    toString = require('./toString');

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeIsFinite = root.isFinite,
    nativeMin = Math.min;

/**
 * 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.
 */
function createRound(methodName) {
  var func = Math[methodName];
  return function(number, precision) {
    number = toNumber(number);
    precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
    if (precision && nativeIsFinite(number)) {
      // Shift with exponential notation to avoid floating-point issues.
      // See [MDN](https://mdn.io/round#Examples) for more details.
      var pair = (toString(number) + 'e').split('e'),
          value = func(pair[0] + 'e' + (+pair[1] + precision));

      pair = (toString(value) + 'e').split('e');
      return +(pair[0] + 'e' + (+pair[1] - precision));
    }
    return func(number);
  };
}

module.exports = createRound;

Version data entries

170 entries across 169 versions & 19 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.59 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.58 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.57 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.56 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.55 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.54 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.53 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.52 node_modules/lodash/_createRound.js
trusty-cms-6.3.1 node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.51 node_modules/lodash/_createRound.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/_createRound.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/_createRound.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/_createRound.js
immosquare-cleaner-0.1.50 node_modules/lodash/_createRound.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/_createRound.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/_createRound.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/_createRound.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/_createRound.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/_createRound.js