Skip to content

Commit

Permalink
fix: set max decimals to 36
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Oct 6, 2023
1 parent 7f8908d commit 5173252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions shared/modules/Numeric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,37 +225,37 @@ describe('Numeric', () => {
it('should compute correct results for division of big numbers', () => {
expect(
new Numeric('175671432', 10).divide('686216', 10).toString(),
).toStrictEqual('256.00019818832554181190762092402392');
).toStrictEqual('256.000198188325541811907620924023922497');

expect(
new Numeric('1756714320', 10)
.divide(new Numeric('686216', 10))
.toString(),
).toStrictEqual('2560.00198188325541811907620924023922');
).toStrictEqual('2560.001981883255418119076209240239224967');

expect(
new Numeric('41756714320', 10)
.divide(new Numeric('6862160', 10))
.toString(),
).toStrictEqual('6085.06859647691106007437891276216235');
).toStrictEqual('6085.068596476911060074378912762162351213');
});

it('should compute correct results for division of negative big numbers', () => {
expect(
new Numeric('175671432', 10).divide('-686216', 10).toString(),
).toStrictEqual('-256.00019818832554181190762092402392');
).toStrictEqual('-256.000198188325541811907620924023922497');

expect(
new Numeric('1756714320', 10)
.divide(new Numeric('-686216', 10))
.toString(),
).toStrictEqual('-2560.00198188325541811907620924023922');
).toStrictEqual('-2560.001981883255418119076209240239224967');

expect(
new Numeric('-41756714320', 10)
.divide(new Numeric('-6862160', 10))
.toString(),
).toStrictEqual('6085.06859647691106007437891276216235');
).toStrictEqual('6085.068596476911060074378912762162351213');
});
});

Expand Down Expand Up @@ -377,15 +377,15 @@ describe('Numeric', () => {
it('should multiply the value by the inverse of conversionRate supplied when second parameter is true', () => {
expect(
new Numeric(10, 10).applyConversionRate(468.5, true).toString(),
).toStrictEqual('0.0213447171824973319103521878335');
).toStrictEqual('0.02134471718249733191035218783351121');
});

it('should multiply the value by the inverse of the BigNumber conversionRate supplied when second parameter is true', () => {
expect(
new Numeric(10, 10)
.applyConversionRate(new BigNumber(468.5, 10), true)
.toString(),
).toStrictEqual('0.0213447171824973319103521878335');
).toStrictEqual('0.02134471718249733191035218783351121');
});
it('should not return 0 if decimals is greater than 20', () => {
expect(
Expand Down
2 changes: 1 addition & 1 deletion shared/modules/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { addHexPrefix } from 'ethereumjs-util';
import { EtherDenomination } from '../constants/common';
import { stripHexPrefix } from './hexstring-utils';

const MAX_DECIMALS_FOR_TOKENS = 32;
const MAX_DECIMALS_FOR_TOKENS = 36;
BigNumber.config({ DECIMAL_PLACES: MAX_DECIMALS_FOR_TOKENS });
export type NumericValue = string | number | BN | BigNumber;
export type NumericBase = 10 | 16;
Expand Down

0 comments on commit 5173252

Please sign in to comment.