forked from TrueCloudLab/frostfs-node
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
87a45983a1
commit
257069a132
1 changed files with 5 additions and 8 deletions
|
@ -1,10 +1,11 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"math/big"
|
||||||
"math"
|
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
|
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/accounting"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -97,12 +98,8 @@ func prettyPrintDecimal(cmd *cobra.Command, decimal *accounting.Decimal) {
|
||||||
cmd.Println("value:", decimal.Value())
|
cmd.Println("value:", decimal.Value())
|
||||||
cmd.Println("precision:", decimal.Precision())
|
cmd.Println("precision:", decimal.Precision())
|
||||||
} else {
|
} else {
|
||||||
// divider = 10^{precision}; v:365, p:2 => 365 / 10^2 = 3.65
|
amountF8 := precision.Convert(decimal.Precision(), 8, big.NewInt(decimal.Value()))
|
||||||
divider := math.Pow(10, float64(decimal.Precision()))
|
|
||||||
|
|
||||||
// %0.8f\n for precision 8
|
cmd.Println(fixedn.ToString(amountF8, 8))
|
||||||
format := fmt.Sprintf("%%0.%df\n", decimal.Precision())
|
|
||||||
|
|
||||||
cmd.Printf(format, float64(decimal.Value())/divider)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue