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
+4.7k List of Golang XML tutorials
+8.9k Golang : Print how to use flag for your application example
+3.8k Golang : Experimental Jawi programming language
+12.9k Golang : concatenate(combine) strings
+7.1k Golang : Auto-generate reply email with text/template package
+6.3k Golang : Dealing with postal or zip code example
+4.2k Golang *File points to a file or directory ?
+16.1k Golang : Qt image viewer example
+4.8k PHP : Get client IP address
+7.1k Golang : Oanda bot with Telegram and RSI example
+32.4k Golang : How to check if slice or array is empty?
+6.2k Golang : Use modern ciphers only in secure connection