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
+7.6k Golang : Accept any number of function arguments with three dots(...)
+28.1k Golang : Get and Set User-Agent examples
+10.9k Golang : Encrypt and decrypt data with x509 crypto
+33.7k Golang : Get file last modified date and time
+8.3k Golang : ffmpeg with os/exec.Command() returns non-zero status
+15.5k Golang : Capture stdout of a child process and act according to the result
+7.8k Golang : HTTP Routing with Goji example
+8.4k Golang : Accessing content anonymously with Tor
+4.9k Fontello : How to load and use fonts?
+11.5k Generate salted password with OpenSSL example
+5.2k Javascript : Generate random key with specific length
+5.9k Golang : How to detect if a sentence ends with a punctuation?