I am trying to print a string with a uint64 but no combination of strconv methods that I use is working.
log.Println("The amount is: " + strconv.Itoa((charge.Amount)))
Gives me:
cannot use charge.Amount (type uint64) as type int in argument to strconv.Itoa
How can I print this string?
strconv.Itoa()expects a value of typeint, so you have to give it that:But know that this may lose precision if
intis 32-bit (whileuint64is 64), also sign-ness is different.strconv.FormatUint()would be better as that expects a value of typeuint64:For more options, see this answer: Golang: format a string without printing?
If your purpose is to just print the value, you don't need to convert it, neither to
intnor tostring, use one of these: