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
+6.1k Golang : Extract sub-strings
+5.4k Golang : Frobnicate or tweaking a string example
+13.3k Golang : Strings comparison
+28.9k Golang : Saving(serializing) and reading file with GOB
+5.1k Golang : Generate Interleaved 2 inch by 5 inch barcode
+9.5k Golang : interface - when and where to use examples
+9.4k Golang : Validate IPv6 example
+9.2k Mac OSX : Get a process/daemon status information
+5.6k Cash Flow : 50 days to pay your credit card debt
+14.4k Golang : Execute function at intervals or after some delay
+12k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+6.8k Golang : Levenshtein distance example