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
+33k Golang : How to check if a date is within certain range?
+5.3k PHP : Hide PHP version information from curl
+20k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+16.9k Golang : Read integer from file into array
+9.1k Golang : Gonum standard normal random numbers example
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+4.8k Golang : How to pass data between controllers with JSON Web Token
+19.3k Golang : Display list of time zones with GMT
+6.6k Golang : Map within a map example
+6.6k Golang : Combine slices of complex numbers and operation example
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+14.4k Golang : How to convert a number to words