-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage-strconv.go
55 lines (38 loc) · 1.04 KB
/
package-strconv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"strconv"
)
func main() {
parseBool, err := strconv.ParseBool("true")
if err == nil {
fmt.Println(parseBool)
} else {
fmt.Println(err.Error())
}
fmt.Println("===============================")
parseFloat, err := strconv.ParseFloat("3.14", 64)
if err == nil {
fmt.Println(parseFloat)
} else {
fmt.Println(err.Error())
}
fmt.Println("===============================")
parseInt, _ := strconv.ParseInt("1000000", 10, 64)
fmt.Println(parseInt)
fmt.Println("===============================")
formatBool := strconv.FormatBool(true)
fmt.Println(formatBool)
// fmt.Println("===============================")
// formatFloat := strconv.FormatFloat(3.14, 10, 2, 64)
// fmt.Println(formatFloat)
fmt.Println("===============================")
formatInt := strconv.FormatInt(777, 10)
fmt.Println(formatInt)
fmt.Println("===============================")
itoa := strconv.Itoa(1000)
fmt.Println(itoa)
fmt.Println("===============================")
atoi, _ := strconv.Atoi("1000")
fmt.Println(atoi)
}