diff --git a/big.js b/big.js index 2541e32..7544ce9 100644 --- a/big.js +++ b/big.js @@ -230,17 +230,18 @@ rm === 3 && (more || !!xc[0]); // Remove any digits after the required precision. - xc.length = sd--; + xc.length = sd; // Round up? if (more) { // Rounding up may mean the previous digit has to be rounded up. - for (; ++xc[sd] > 9;) { + for (; ++xc[--sd] > 9;) { xc[sd] = 0; - if (!sd--) { + if (sd === 0) { ++x.e; xc.unshift(1); + break; } } } diff --git a/big.mjs b/big.mjs index 7378d38..0ed3284 100644 --- a/big.mjs +++ b/big.mjs @@ -227,17 +227,18 @@ function round(x, sd, rm, more) { rm === 3 && (more || !!xc[0]); // Remove any digits after the required precision. - xc.length = sd--; + xc.length = sd; // Round up? if (more) { // Rounding up may mean the previous digit has to be rounded up. - for (; ++xc[sd] > 9;) { + for (; ++xc[--sd] > 9;) { xc[sd] = 0; - if (!sd--) { + if (sd === 0) { ++x.e; xc.unshift(1); + break; } } } diff --git a/test/methods/round.js b/test/methods/round.js index d1a98b1..621bf19 100644 --- a/test/methods/round.js +++ b/test/methods/round.js @@ -5286,4 +5286,7 @@ test('round', function () { t('0', '98765000', -10, 1); t('0', '98765000', -10, 2); t('10000000000', '98765000', -10, 3); + + // #191 + test.isTrue(new Big('9.9').round().c['-1'] === u); });