number parsing _ golang
Parsing numbers from strings is a basic but common task in many programs; here's how to do it in 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) }
1.234 123 456 789 135 strconv.ParseInt: parsing "wat": invalid syntax
总结 :
1 : ...
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。