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
+5.2k Golang : Regular Expression find string example
+6.5k Golang : Sieve of Eratosthenes algorithm
+3.9k Golang : Extract unicode string from another unicode string example
+13.2k Golang : Get own process identifier
+14.1k Golang : Simple client server example
+6.8k Golang : Embed secret text string into binary(executable) file
+9.2k CodeIgniter : How to check if a session exist in PHP?
+16.9k Golang : simulate tail -f or read last line from log file example
+8.3k Golang : Surveillance with web camera and OpenCV
+9.7k Golang : How to determine if user agent is a mobile device example
+7.5k Golang : Sort and reverse sort a slice of runes