Skip to content

Commit 609d5f0

Browse files
authored
fix: parseUnits for with big formatted amounts (#740)
1 parent 17c455c commit 609d5f0

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

.changeset/spotty-ladybugs-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@fuel-ts/math": patch
3+
---
4+
5+
Fix parseUnits for bit amounts

packages/math/src/bn.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ describe('Math - BN', () => {
467467
expect(bn.parseUnits('100.00002').toHex()).toEqual(bn('100000020000').toHex());
468468
expect(bn.parseUnits('100,100.00002').toHex()).toEqual(bn('100100000020000').toHex());
469469
expect(bn.parseUnits('100,100.00002', 5).toHex()).toEqual(bn('10010000002').toHex());
470+
expect(bn.parseUnits('1,100,100.00002', 5).toHex()).toEqual(bn('110010000002').toHex());
471+
expect(bn.parseUnits('100,100,100.00002', 5).toHex()).toEqual(bn('10010010000002').toHex());
470472
expect(bn.parseUnits('.').toHex()).toEqual(bn('0').toHex());
471473
expect(bn.parseUnits('.', 5).toHex()).toEqual(bn('0').toHex());
472474

packages/math/src/bn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,6 @@ bn.parseUnits = (value: string, units: number = DECIMAL_UNITS): BN => {
269269

270270
const decimals = Array.from({ length: units }).fill('0');
271271
decimals.splice(0, length, valueDecimals);
272-
const amount = `${valueUnits.replace(',', '')}${decimals.join('')}`;
272+
const amount = `${valueUnits.replaceAll(',', '')}${decimals.join('')}`;
273273
return bn(amount);
274274
};

0 commit comments

Comments
 (0)