Go标准库解读-strconv

strconv

Package strconv implements conversions to and from string representations of basic data types.
strconv:字符串与基本数据类型的相互转换。

append追加函数

func AppendBool(dst []byte, b bool) []byte
func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize) []byte//fmt::显示方式E/e prec:小数精度  bitSize:float32/64 
b32 := []byte("float32:")
    b32 = strconv.AppendFloat(b32, 3.1415926535, 'E', -1, 32)
    fmt.Println(string(b32))

    b64 := []byte("float64:")
    b64 = strconv.AppendFloat(b64, 3.1415926535, 'E', -1, 64)
    fmt.Println(string(b64))
//float32:3.1415927E+00
//float64:3.1415926535E+00
func AppendInt(dst []byte, i int64, base int) []btye
func AppendQuote(dst []byte, s string) []btye
func AppendQuoteRune(dst []byte, r rune) []btye

转换

func Atoi(s string) (int, error)//

func FormatFloat(f float64, fmt byte, prec, bitSize int) string//fmt::显示方式E/e prec:(-1表示最大精度)小数精度  bitSize:float32/64 
s32 := strconv.FormatFloat(v, 'e', -1, 32)
fmt.Printf("%T, %v\n", s32, s32)
s64 := strconv.FormatFloat(v, 'E', -1, 64)
fmt.Printf("%T, %v\n", s64, s64)
//string, 3.1415927e+00
//string, 3.1415926535E+00

func FormatInt(i int64, base int) string
func FormatUint(i int64, base int) string
func Itoa(i int) string

func ParseBool(str string) (bool, error)
func ParseFloat(s string, bitSize int) (float64, error)
func ParseInt(s string, base int, bitSize int) (int64, error)
func ParseUint(s string, base int, bitSize int) (int64, error)

你可能感兴趣的:(Go标准库解读-strconv)