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
+13k Golang : Linear algebra and matrix calculation example
+11.3k Golang : Concurrency and goroutine example
+6.5k How to let Facebook Login button redirect to a particular URL ?
+14.8k Golang : How to check if IP address is in range
+9.7k Golang : Convert octal value to string to deal with leading zero problem
+16.8k Golang : Find file size(disk usage) with filepath.Walk
+23.2k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+17.6k Golang : How to log each HTTP request to your web server?
+4.8k Golang : Display packages names during compilation
+7.1k Golang : Check to see if *File is a file or directory
+8.5k Golang : Heap sort example