string型からint64型へ変換する方法
// int64
var strInt64 string = "9223372036854775807"
// strconv.ParseInt(文字列, 基数(10進数),ビット長)
convertedStrInt64, _ := strconv.ParseInt(strInt64, 10, 64)
9223372036854775807
はint64
の最大数です
int64 is the set of all signed 64-bit integers. Range: -9223372036854775808 through 9223372036854775807.
string型からuint64型へ変換する方法
// uint64
var strUint64 string = "18446744073709551615"
// strconv.ParseUint(文字列, 基数(10進数),ビット長)
convertedStrUint64, _ := strconv.ParseUint(strUint64, 10, 64)
18446744073709551615
はuint64の最大数です
uint64 is the set of all unsigned 64-bit integers. Range: 0 through 18446744073709551615.
Go Playground
package main
import (
"strconv"
"fmt"
"reflect"
)
func main() {
// int64
var strInt64 string = "9223372036854775807"
convertedStrInt64, _ := strconv.ParseInt(strInt64, 10, 64)
fmt.Printf("%v with type %s \n", convertedStrInt64, reflect.TypeOf(convertedStrInt64))
// uint64
var strUint64 string = "18446744073709551615"
convertedStrUint64, _ := strconv.ParseUint(strUint64, 10, 64)
fmt.Printf("%v with type %s \n", convertedStrUint64, reflect.TypeOf(convertedStrUint64))
}
実行結果
9223372036854775807 with type int64
18446744073709551615 with type uint64