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
+19.2k Golang : Determine if directory is empty with os.File.Readdir() function
+14.9k Golang : Get digits from integer before and after given position example
+5.7k Javascript : Get operating system and browser information
+8.6k Golang : How to use Gorilla webtoolkit context package properly
+5.2k Linux/Unix/PHP : Restart PHP-FPM
+11.4k Golang : Convert decimal number(integer) to IPv4 address
+4.7k Python : Create Whois client or function example
+21.4k Golang : Convert seconds to minutes and remainder seconds
+6.5k Golang : Levenshtein distance example
+14.6k nginx: [emerg] unknown directive "ssl"
+6.5k Golang : constant 20013 overflows byte error message
+35.1k Golang : Get file last modified date and time