@kikuchan/decimal 0.1.0-alpha.2 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +5 -1
- package/tests/decimal.spec.ts +10 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -407,7 +407,11 @@ class DecimalImpl implements Decimal {
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
#stripTrailingZeros$(): this {
|
|
410
|
-
if (this.
|
|
410
|
+
if (this.coeff === 0n) {
|
|
411
|
+
this.digits = 0n;
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
if (this.digits <= 0n) return this;
|
|
411
415
|
while (this.digits > 0n && this.coeff % 10n === 0n) {
|
|
412
416
|
this.coeff /= 10n;
|
|
413
417
|
this.digits -= 1n;
|
package/tests/decimal.spec.ts
CHANGED
|
@@ -1186,11 +1186,18 @@ describe('Decimal boundaries', () => {
|
|
|
1186
1186
|
expect(clamped.eq(original)).toBe(true);
|
|
1187
1187
|
});
|
|
1188
1188
|
|
|
1189
|
-
it('
|
|
1189
|
+
it('compresses zero to standard form with rescale', () => {
|
|
1190
1190
|
const value = Decimal({ coeff: 0n, digits: 5n });
|
|
1191
1191
|
const compressed = value.rescale();
|
|
1192
|
-
expect(compressed.digits).toBe(
|
|
1193
|
-
expect(compressed.toString()).toBe('0
|
|
1192
|
+
expect(compressed.digits).toBe(0n);
|
|
1193
|
+
expect(compressed.toString()).toBe('0');
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
it('compresses zero with negative exponent to standard form with rescale', () => {
|
|
1197
|
+
const value = Decimal({ coeff: 0n, digits: -5n });
|
|
1198
|
+
const compressed = value.rescale();
|
|
1199
|
+
expect(compressed.digits).toBe(0n);
|
|
1200
|
+
expect(compressed.toString()).toBe('0');
|
|
1194
1201
|
});
|
|
1195
1202
|
});
|
|
1196
1203
|
|