wallet/pkg/tron/tron_util.go

32 lines
740 B
Go
Raw Normal View History

2024-08-31 14:46:20 +00:00
package tron
import (
"fmt"
"math"
"math/big"
"strconv"
"github.com/fbsobreira/gotron-sdk/pkg/common/decimals"
)
func FormatSum(amount int64, decimals int64) (string, float64) {
value := float64(amount) / math.Pow(10, float64(decimals))
return fmt.Sprintf("%.2f", value), value
}
func FormatSumString(amount string, dec int64) (string, float64) {
floatValue, _ := strconv.ParseFloat(amount, 64)
value := floatValue / math.Pow(10, float64(dec))
return fmt.Sprintf("%.2f", value), value
}
func Float64ToDecimals(amount float64, dec int64) *big.Int {
value, _ := decimals.ApplyDecimals(big.NewFloat(amount), dec)
return value
}
func ToTronAddress(eth []byte) []byte {
prefix := []byte{0x41}
return append(prefix, eth...)
}