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
+10.2k Golang : Resolve domain name to IP4 and IP6 addresses.
+5.6k PHP : Get client IP address
+7.8k Golang : HTTP Server Example
+16k Golang : Execute terminal command to remote machine example
+5.6k Facebook : How to force facebook to scrape latest URL link data?
+13.9k Golang : Send email with attachment(RFC2822) using Gmail API example
+6.5k Mac/Linux/Windows : Get CPU information from command line
+5.6k nginx : force all pages to be SSL
+21.6k Golang : Convert seconds to minutes and remainder seconds
+10.5k PHP : Convert(cast) bigInt to string
+17.2k Golang : Upload/Receive file progress indicator