Skip to content

Commit 824939a

Browse files
authored
fix(NODE-3021): fix a long standing bug in Decimal128.fromString() (#458)
1 parent b46ab5f commit 824939a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/decimal128.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export class Decimal128 {
304304
lastDigit = nDigitsStored - 1;
305305
significantDigits = nDigits;
306306
if (significantDigits !== 1) {
307-
while (representation[firstNonZero + significantDigits - 1] === '0') {
307+
while (digits[firstNonZero + significantDigits - 1] === 0) {
308308
significantDigits = significantDigits - 1;
309309
}
310310
}

test/node/decimal128_tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ describe('Decimal128', function () {
12101210
expect(new Decimal128('00').toString()).to.equal('0');
12111211
expect(new Decimal128('0.5').toString()).to.equal('0.5');
12121212
expect(new Decimal128('-0.5').toString()).to.equal('-0.5');
1213+
expect(new Decimal128('-0.0097').toString()).to.equal('-0.0097');
1214+
expect(new Decimal128('-0.0011').toString()).to.equal('-0.0011');
1215+
expect(new Decimal128('-0.00110').toString()).to.equal('-0.00110');
1216+
expect(new Decimal128('0.0011').toString()).to.equal('0.0011');
1217+
expect(new Decimal128('0.00110').toString()).to.equal('0.00110');
12131218
expect(new Decimal128('-1e400').toString()).to.equal('-1E+400');
12141219
done();
12151220
});

0 commit comments

Comments
 (0)