Skip to content

Commit

Permalink
Merge pull request #20 from consenlabs/number-format-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kaichen authored Apr 22, 2021
2 parents f655c6f + acea457 commit 981bd41
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { BigNumber } from '@0xproject/utils'
BigNumber.config({
ROUNDING_MODE: BigNumber.ROUND_FLOOR,
DECIMAL_PLACES: 18,
FORMAT: {
decimalSeparator: '.',
groupSeparator: '',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0,
},
})

export { BigNumber }
Expand Down Expand Up @@ -39,5 +47,5 @@ export const fromUnitToDecimalBN = (balance: number | string, decimal: number):

// truncate out of precision part
export const truncateAmount = (amount: number | string, precision: number): number => {
return toBN(toBN(amount).toFormat(precision)).toNumber()
return +toBN(amount).toFixed(precision)
}

0 comments on commit 981bd41

Please sign in to comment.