From 257069a132d4d7a191426365ad83b3598f69face Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 24 Jan 2022 20:05:09 +0300 Subject: [PATCH] [#1084] cli/accounting: Convert balance response to Fixed8 After recent changes balance response contains contract precision. Convert balance response to Fixed8. Use `fixedn.ToString` function to print the converted value. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/accounting.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/neofs-cli/modules/accounting.go b/cmd/neofs-cli/modules/accounting.go index e7c9f2848..0d4ec15d0 100644 --- a/cmd/neofs-cli/modules/accounting.go +++ b/cmd/neofs-cli/modules/accounting.go @@ -1,10 +1,11 @@ package cmd import ( - "fmt" - "math" + "math/big" + "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client" + "github.com/nspcc-dev/neofs-node/pkg/util/precision" "github.com/nspcc-dev/neofs-sdk-go/accounting" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/spf13/cobra" @@ -97,12 +98,8 @@ func prettyPrintDecimal(cmd *cobra.Command, decimal *accounting.Decimal) { cmd.Println("value:", decimal.Value()) cmd.Println("precision:", decimal.Precision()) } else { - // divider = 10^{precision}; v:365, p:2 => 365 / 10^2 = 3.65 - divider := math.Pow(10, float64(decimal.Precision())) + amountF8 := precision.Convert(decimal.Precision(), 8, big.NewInt(decimal.Value())) - // %0.8f\n for precision 8 - format := fmt.Sprintf("%%0.%df\n", decimal.Precision()) - - cmd.Printf(format, float64(decimal.Value())/divider) + cmd.Println(fixedn.ToString(amountF8, 8)) } }