Skip to content

Commit

Permalink
+ 修复ToFil、FromFil转换的精度丢失问题
Browse files Browse the repository at this point in the history
  • Loading branch information
赵波 committed Aug 27, 2020
1 parent 829cde8 commit 8dd48ea
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/shopspring/decimal"

// 将大数的Fil转换为小数
func ToFil(v decimal.Decimal) decimal.Decimal {
return v.Div(decimal.NewFromInt(10).Pow(decimal.NewFromInt(18)))
return v.DivRound(decimal.NewFromInt(10).Pow(decimal.NewFromInt(18)), 18)
}

// 将小数的Fil转换为大数
Expand Down
1 change: 1 addition & 0 deletions wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestClient_WalletBalance(t *testing.T) {

t.Log(b.String())
t.Log(ToFil(b).String())
t.Log(FromFil(ToFil(b)).String())
}

func TestClient_WalletNew(t *testing.T) {
Expand Down

0 comments on commit 8dd48ea

Please sign in to comment.