printing - How can I print out an constant uint64 in Go using fmt? -
i tried:
fmt.printf("%d", math.maxuint64)
but got following error message:
constant 18446744073709551615 overflows int
how can fix this? thanks!
math.maxuint64
constant, not int64. try instead:
fmt.printf("%d", uint64(num))
the issue here constant untyped. constant assume type depending on context in used. in case, being used interface{} compiler has no way of knowing concrete type want use. integer constants, defaults int
. since constant overflows int, compile time error. passing uint64(num)
, informing compiler want value treated uint64
.
note particular constant fit in uint64 , uint. bigger standard int64.
Comments
Post a Comment