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
+32.4k Golang : How to check if slice or array is empty?
+21.4k Golang : Test file read write permission example
+14.3k Golang : invalid character ',' looking for beginning of value
+10.3k Golang : Concurrency and goroutine example
+24.2k Golang : How to read integer value from standard input ?
+10.8k Golang : Simple client-server HMAC authentication without SSL example
+13.7k Golang : Get HTTP protocol version example
+4.3k Golang : How to deal with configuration data?
+11.7k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+40.5k Golang : Convert []byte to image
+14.6k Golang : Update database with GORM example