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
+2.8k Javascript : Detect when console is activated and do something about it
+11.9k Golang : GUI with Qt and OpenCV to capture image from camera
+4.6k Golang : How to determine if request or crawl is from Google robots
+69.8k Golang : How to convert character to ASCII and back
+4.9k Golang : Check if password length meet the requirement
+3.8k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+26.3k Golang : Get first few and last few characters from string
+4.3k Fontello : How to load and use fonts?
+36.5k Golang : How to read CSV file
+4.6k Apt-get to install and uninstall Golang
+9.4k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+5.8k Golang : Configure Apache and NGINX to access your Go service example