0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

16进制转换10进制

Posted at
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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?