Skip to content

Commit

Permalink
doc: update golang.md (#802)
Browse files Browse the repository at this point in the history
类型转换中补充了字符串与其他类型相互转换的方法
  • Loading branch information
qjksxy authored Jul 17, 2024
1 parent fac5af1 commit 708329d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions docs/golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,26 @@ u := uint(i)
s := string(i)
```

#### 如何获取int字符串?
#### 字符串与其他类型的相互转换

```go
i := 90
// 需要导入“strconv”
s := strconv.Itoa(i)
fmt.Println(s) // Outputs: 90
// 字符串转其他类型
str := "90"
// 整数类型
i, err := strconv.Atoi(str)
if err != nil {
fmt.Println("转换错误:", err)
} else {
fmt.Println(i)
}
// 浮点类型
f, err := strconv.ParseFloat(str, 64)
// []byte 类型
bytes := []byte(str)
// 其他类型转字符串
str = strconv.Itoa(i)
str = strconv.FormatFloat(f, 'f', 2, 64)
str = string(bytes[:])
```

Golang 字符串
Expand Down

0 comments on commit 708329d

Please sign in to comment.