gouint64

strconv.ParseInt: parsing "18446744073709551615": value out of range


Is it a normal behavior when parsing uint64 max value with strconv.ParseInt?

i, err := strconv.ParseInt("18446744073709551615", 10, 64)
fmt.Println(i, err)

I got an error: "strconv.ParseInt: parsing "18446744073709551615": value out of range", when maximum allowed value for uint64 is: 18446744073709551615

Can you explain such behavior?

https://golang.org/src/builtin/builtin.go?s=1026:1044#L26


Solution

  • Call ParseUint to parse an unsigned integer.

    The ParseInt function parses signed integers. The maximum signed integer is 9223372036854775807.