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
+7.6k Golang : Load DSA public key from file example
+32.4k Golang : Regular Expression for alphanumeric and underscore
+5.1k Golang : Pad file extension automagically
+18.3k Golang : Generate thumbnails from images
+16.2k Golang : Execute terminal command to remote machine example
+5.1k Python : Convert(cast) string to bytes example
+10.7k Golang : Create Temporary File
+5.4k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+6.4k Golang : Skip or discard items of non-interest when iterating example
+6.8k Web : How to see your website from different countries?
+10.4k Golang : Flip coin example