Golang konvertieren INT in String
str := strconv.Itoa(12)
Splendid-est Swan
str := strconv.Itoa(12)
s := strconv.Itoa(i)
// also
s := strconv.FormatInt(i, 10)
// and also
s := fmt.Sprintf("%d", i)
f, err := strconv.ParseFloat("3.1415", 64)
s := "97"
n, err := strconv.ParseInt(s, 10, 64)
if err == nil {
fmt.Printf("%d of type %T", n, n)
}
package main
import (
"strconv"
"fmt"
)
func main() {
t := strconv.Itoa(123)
fmt.Println(t)
}
Golang program that casts float to int
package main
import "fmt"
func main() {
size := 1.2
fmt.Println(size)
// Convert to an int with a cast.
i := int(size)
fmt.Println(i)
}
Output
1.2
1