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
+21.7k Golang : Use TLS version 1.2 and enforce server security configuration over client
+9.8k Golang : Sort and reverse sort a slice of integers
+21.6k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+23.5k Find and replace a character in a string in Go
+13.8k Golang : convert rune to unicode hexadecimal value and back to rune character
+9.2k Golang : Apply Histogram Equalization to color images
+5k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+8.7k Golang : HTTP Routing with Goji example
+5.2k Golang : Reclaim memory occupied by make() example
+14.3k Golang : Find network of an IP address
+21.5k SSL : How to check if current certificate is sha1 or sha2
+33.8k Golang : Call a function after some delay(time.Sleep and Tick)