0130-Go-数值解析

环境

  • Time 2022-08-25
  • Go 1.19

前言

说明

参考:https://gobyexample.com/number-parsing

目标

使用 Go 语言的数值解析。

示例

package main

import (
    "fmt"
    "strconv"
)

func main() {

    f, _ := strconv.ParseFloat("1.234", 64)
    fmt.Println(f)

    i, _ := strconv.ParseInt("123", 0, 64)
    fmt.Println(i)

    d, _ := strconv.ParseInt("0x1c8", 0, 64)
    fmt.Println(d)

    u, _ := strconv.ParseUint("789", 0, 64)
    fmt.Println(u)

    k, _ := strconv.Atoi("135")
    fmt.Println(k)

    _, e := strconv.Atoi("wat")
    fmt.Println(e)
}

总结

使用 Go 语言的数值解析。

附录

posted @ 2022-11-28 22:24  jiangbo4444  阅读(21)  评论(0)    收藏  举报