Skip to content

Commit

Permalink
Fix bug on parsing coin amount and converting to int coins
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Jan 14, 2025
1 parent 5cf6593 commit 11c9044
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.2.26",
"version": "0.2.27",
"description": "The JavaScript SDK for Initia",
"license": "Apache-2.0",
"author": "Initia Foundation",
Expand Down
8 changes: 4 additions & 4 deletions src/core/Coin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSONSerializable } from '../util/json'
import { Denom } from './Denom'
import { num, checkDecimal } from './num'
import { num, checkDecimal, BigNumber } from './num'
import { Coin as Coin_pb } from '@initia/initia.proto/cosmos/base/v1beta1/coin'

/**
Expand All @@ -23,22 +23,22 @@ export class Coin extends JSONSerializable<Coin.Amino, Coin.Data, Coin.Proto> {
amount: number | string
) {
super()
this.amount = num(amount).toString()
this.amount = num(amount).toFixed()
this.isDecimal = checkDecimal(amount)
}

/**
* Turns the Coin into an Integer coin.
*/
public toIntCoin(): Coin {
return new Coin(this.denom, num(this.amount).toFixed())
return new Coin(this.denom, num(this.amount).toFixed(0))
}

/**
* Turns the Coin into an Integer coin with ceiling the amount.
*/
public toIntCeilCoin(): Coin {
return new Coin(this.denom, num(this.amount).toFixed(0, 2))
return new Coin(this.denom, num(this.amount).toFixed(0, BigNumber.ROUND_CEIL))
}

/**
Expand Down

0 comments on commit 11c9044

Please sign in to comment.