From c98db79defcae853fe1070212515b9af8ee088ac Mon Sep 17 00:00:00 2001 From: hconn-riparian <121891959+hconn-riparian@users.noreply.github.com> Date: Tue, 7 Feb 2023 14:10:43 -0500 Subject: [PATCH 1/2] fix rounding error --- src/decimal128.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/decimal128.ts b/src/decimal128.ts index 55543a769..9dd72b4fb 100644 --- a/src/decimal128.ts +++ b/src/decimal128.ts @@ -434,6 +434,8 @@ export class Decimal128 extends BSONValue { return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER); } } + } else { + break; } } } From ca1cd39920741ed1098dc131ae2451bf23b9fd3f Mon Sep 17 00:00:00 2001 From: hconn-riparian <121891959+hconn-riparian@users.noreply.github.com> Date: Tue, 7 Feb 2023 14:17:05 -0500 Subject: [PATCH 2/2] unit test rounding fix --- test/node/decimal128_tests.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/node/decimal128_tests.js b/test/node/decimal128_tests.js index c427c726d..2f7394be4 100644 --- a/test/node/decimal128_tests.js +++ b/test/node/decimal128_tests.js @@ -477,6 +477,9 @@ describe('Decimal128', function () { expect(bytes).to.deep.equal(result.bytes); + result = Decimal128.fromString('37.499999999999999196428571428571375'); + expect(result.toString()).to.deep.equal('37.49999999999999919642857142857138'); + // // Create decimal from string value 15E-6177 // result = Decimal128.fromString('15E-6177'); // bytes = Buffer.from(