fix: limit the precision when the precision is negative (#4085)

This commit is contained in:
LinWei
2018-11-28 23:12:21 +08:00
committed by John-David Dalton
parent c3740e0847
commit 377e2d87c8

View File

@@ -8,7 +8,7 @@
function createRound(methodName) {
const func = Math[methodName]
return (number, precision) => {
precision = precision == null ? 0 : Math.min(precision, 292)
precision = precision == null ? 0 : (precision >= 0 ? Math.min(precision, 292) : Math.max(precision, -292))
if (precision) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.