Skip to content

Commit

Permalink
fix(NODE-3021): fix a long standing bug in Decimal128.fromString() (#458
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tzhuan authored Sep 9, 2021
1 parent b46ab5f commit 824939a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/decimal128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class Decimal128 {
lastDigit = nDigitsStored - 1;
significantDigits = nDigits;
if (significantDigits !== 1) {
while (representation[firstNonZero + significantDigits - 1] === '0') {
while (digits[firstNonZero + significantDigits - 1] === 0) {
significantDigits = significantDigits - 1;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/node/decimal128_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,11 @@ describe('Decimal128', function () {
expect(new Decimal128('00').toString()).to.equal('0');
expect(new Decimal128('0.5').toString()).to.equal('0.5');
expect(new Decimal128('-0.5').toString()).to.equal('-0.5');
expect(new Decimal128('-0.0097').toString()).to.equal('-0.0097');
expect(new Decimal128('-0.0011').toString()).to.equal('-0.0011');
expect(new Decimal128('-0.00110').toString()).to.equal('-0.00110');
expect(new Decimal128('0.0011').toString()).to.equal('0.0011');
expect(new Decimal128('0.00110').toString()).to.equal('0.00110');
expect(new Decimal128('-1e400').toString()).to.equal('-1E+400');
done();
});
Expand Down

0 comments on commit 824939a

Please sign in to comment.