Skip to content

Commit

Permalink
Fix rounding in division / multiplication of filecoin numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
navFooh committed Jun 26, 2024
1 parent 34a9971 commit 15c4043
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/filecoin-number/src/FilecoinNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ export class FilecoinNumber extends BigNumber {
* Returns a copy of this FilecoinNumber divided by the supplied value n
*/
div(n: BigNumber.Value): FilecoinNumber {
return new FilecoinNumber(super.div(n), 'fil', this.coinType, this.unit)
const bigNr = super.div(n).dp(18, BigNumber.ROUND_DOWN)
return new FilecoinNumber(bigNr, 'fil', this.coinType, this.unit)
}

/**
Expand All @@ -333,7 +334,8 @@ export class FilecoinNumber extends BigNumber {
* Returns a copy of this FilecoinNumber multiplied by the supplied value n
*/
times(n: BigNumber.Value): FilecoinNumber {
return new FilecoinNumber(super.times(n), 'fil', this.coinType, this.unit)
const bigNr = super.times(n).dp(18, BigNumber.ROUND_DOWN)
return new FilecoinNumber(bigNr, 'fil', this.coinType, this.unit)
}

/**
Expand Down

0 comments on commit 15c4043

Please sign in to comment.