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
+11.8k Golang : Display a text file line by line with line number example
+10.9k PHP : Convert(cast) bigInt to string
+12.4k Golang : Print UTF-8 fonts on image example
+5k HTTP common errors and their meaning explained
+17.7k Golang : Clone with pointer and modify value
+25.2k Golang : Create PDF file from HTML file
+10.5k Golang : Generate random integer or float number
+4.7k Javascript : Detect when console is activated and do something about it
+11.2k Golang : Roll the dice example
+23k Golang : Gorilla mux routing example
+33.1k Golang : How to check if a date is within certain range?