diff --git a/lodash.js b/lodash.js index e03f762b0..aeb94c13b 100644 --- a/lodash.js +++ b/lodash.js @@ -4148,15 +4148,15 @@ function createRound(methodName) { var func = Math[methodName]; return function(number, precision) { + number = toNumber(number); precision = precision ? toInteger(precision) : 0; if (precision) { // Shift with exponential notation to avoid floating-point issues. // See [MDN](https://mdn.io/round#Examples) for more details. - var pair = (+number + 'e').split('e'), - value = func(pair[0] + 'e' + (+pair[1] + precision)); - + var pair = (toString(number) + 'e').split('e'), + value = toString(func(pair[0] + 'e' + (+pair[1] + precision))); pair = (value + 'e').split('e'); - return +(pair[0] + 'e' + (pair[1] - precision)); + return +(pair[0] + 'e' + (+pair[1] - precision)); } return func(number); }; diff --git a/test/test.js b/test/test.js index 0c537da9f..bbdac2f5e 100644 --- a/test/test.js +++ b/test/test.js @@ -16130,7 +16130,19 @@ actual = func('5e1e1', 1); assert.deepEqual(actual, NaN); + }); + QUnit.test('`_.' + methodName + '` should preserve sign of `0`', function(assert) { + assert.expect(1); + + var values = [[0], [-0], ['0'], ['-0'], [0, 1], [-0, 1], ['0', 1], ['-0', 1]], + expected = [Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity, Infinity, -Infinity]; + + var actual = lodashStable.map(values, function(args) { + return 1 / func.apply(undefined, args); + }); + + assert.deepEqual(actual, expected); }); });