parse attofil to fil

This commit is contained in:
Jennifer Wang 2021-10-26 19:32:16 -04:00
parent 6607019788
commit 18834de7d0
4 changed files with 14 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package types
import (
"encoding"
"fmt"
"github.com/filecoin-project/go-state-types/abi"
"math/big"
"strings"
@ -122,6 +123,13 @@ func ParseFIL(s string) (FIL, error) {
return FIL{r.Num()}, nil
}
func ParseAttoFilToFIL(atto abi.TokenAmount) string {
vfil := big.NewFloat(0)
vfil.Add(vfil, new(big.Float).SetInt(atto.Int))
return new(big.Float).Quo(vfil, big.NewFloat(float64(build.FilecoinPrecision))).String() + " FIL"
}
func MustParseFIL(s string) FIL {
n, err := ParseFIL(s)
if err != nil {

View File

@ -647,9 +647,9 @@ var walletMarketWithdraw = &cli.Command{
return err
}
fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amt) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amt)
fmt.Printf("Note that this is less than the requested amount of %s \n", types.ParseAttoFilToFIL(amt))
}
}

View File

@ -306,9 +306,9 @@ var actorWithdrawCmd = &cli.Command{
return err
}
fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amount) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amount)
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", types.ParseAttoFilToFIL(amount))
}
}

View File

@ -151,9 +151,9 @@ var actorWithdrawCmd = &cli.Command{
return err
}
fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amount) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amount)
fmt.Printf("Note that this is less than the requested amount of %s \n", types.ParseAttoFilToFIL(amount))
}
}