Golang : Convert(cast) string to int64
Problem :
You want to convert(cast) a string to big integer value(int64) for display.
Solution :
Use strconv.ParseInt() function to convert the string value to int64 type. For example :
package main
import (
"fmt"
"reflect"
"strconv"
)
func main() {
var str string = "123456789"
sixtyFour, err := strconv.ParseInt(str, 10, 64) // use base 10 for sanity
if err != nil {
fmt.Println(err)
}
fmt.Printf("The type of sixtyFour is %v \n", reflect.TypeOf(sixtyFour))
}
Output :
The type of sixtyFour is int64
Reference :
See also : Golang : Convert(cast) int64 to string
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+12.1k Golang : How to check if a string starts or ends with certain characters or words?
+28.3k Golang : Read, Write(Create) and Delete Cookie example
+35.7k Golang : Get file last modified date and time
+22.8k Golang : Gorilla mux routing example
+7k Golang : A simple forex opportunities scanner
+33.5k Golang : All update packages with go get command
+5.2k Python : Convert(cast) string to bytes example
+25.7k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+10.4k Golang : Select region of interest with mouse click and crop from image
+7.4k Golang : Shuffle strings array
+40.8k Golang : How to check if a string contains another sub-string?
+15.4k Golang : How to convert(cast) IP address to string?