Skip to content

Convert string to int64 in Golang

Another day, another type conversion in Golang ūüôā Today we want to convert a number from string into int64 type, using ParseInt method from strconv package:

func ParseInt(s string, base int, bitSize int) (i int64, err error)

Simple example of conversion:

package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {

	numberInString := "234567"

	numberInInt64, err := strconv.ParseInt(numberInString, 10, 64)
	if err != nil {
		return
	}

	fmt.Println(numberInInt64)
	fmt.Println(reflect.TypeOf(numberInInt64))
}

Leave a Reply

Your email address will not be published. Required fields are marked *