package main
import (
"fmt"
"strconv"
)
func main() {
hex := "0xC40C5253"
val := hex[2:]
n, err := strconv.ParseUint(val, 16, 32)
if err != nil {
panic(err)
}
n2 := uint32(n)
fmt.Print(n2)
}
float64 convert to string
package main
import "fmt"
import "strconv"
func FloatToString(input_num float64) string {
// to convert a float number to a string
return strconv.FormatFloat(input_num, 'f', 6, 64)
}
func main() {
fmt.Println(FloatToString(21312421.213123))
}
string hex convert to big.Int
hexToBigInt("0x12a05f200")
func hexToBigInt(hex string) *big.Int {
n := new(big.Int)
n, _ = n.SetString(hex[2:], 16)
return n
}
参考:
https://play.golang.org/p/IL76yCuzsMh