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.6k Golang : Get UDP client IP address and differentiate clients by port number
+8.5k Golang : Combine slices but preserve order example
+9.1k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+7.7k Golang : What fmt.Println() can do and println() cannot do
+5k PHP : See installed compiled-in-modules
+5.9k Golang : Process non-XML/JSON formatted ASCII text file example
+5.8k Golang : Create new color from command line parameters
+7.7k Javascript : Put image into Chrome browser's console
+17.1k Golang : Check if IP address is version 4 or 6
+6.6k Golang : Muxing with Martini example
+8.3k Golang : Convert(cast) []byte to io.Reader type
+12k Golang : Encrypt and decrypt data with x509 crypto