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
+5k Golang : Shuffle array of list
+23.9k Golang : Convert uint value to string type
+9.2k Android Studio : Checkbox for user to select options example
+10.7k Golang : Perform sanity checks on filename example
+16.1k Golang : Multi threading or run two processes or more example
+12.2k Golang : Read XML elements data with xml.CharData example
+6.8k Golang : Scan files for certain pattern and rename part of the files
+8.2k Golang : does not implement flag.Value (missing Set method)
+6.3k Golang : File system scanning
+4.2k Golang *File points to a file or directory ?
+31.2k Golang : Regular Expression for alphanumeric and underscore
+3.8k Linux : How to set root password in Linux Mint