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 : Extract sub-strings
+21k Golang : How to read JPG(JPEG), GIF and PNG files ?
+28.7k Golang : Calculate percentage change of two values
+11.5k Golang : Transform comma separated string to slice example
+10k Golang : Find age or leap age from date of birth example
+12.5k Javascript : Prompt confirmation before exit
+5.7k Fix sudo yum hang problem with no output or error messages
+13.3k Golang : package is not in GOROOT during compilation
+14.2k Golang : How to convert(cast) IP address to string?
+4.7k Unix/Linux : Get reboot history or check when was the last reboot date
+4.3k Golang : Detect words using using consecutive letters in a given string
+32.3k Golang : How to check if slice or array is empty?