strconv.Itoa() expects a value of type int, so you have to give it that:
log.Println("The amount is: " + strconv.Itoa(int(charge.Amount)))
But know that this may lose precision if int is 32-bit (while uint64 is 64), also sign-ness is different. strconv.FormatUint() would be better as that expects a value of type uint64:
log.Println("The amount is: " + strconv.FormatUint(charge.Amount, 10))
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 int nor to string, use one of these:
log.Println("The amount is:", charge.Amount)
log.Printf("The amount is: %d\n", charge.Amount)
Answer from icza on Stack Overflowgo - How to convert uint64 to string - Stack Overflow
How to convert an int value to string in Go? - Stack Overflow
GMS "unable to convert string "" to int64" Error, Not Trying to convert Anything
Convert string to int64 when value may be > flintmax?
I've been reading some articles online why converting an int64 value to string using a combination of int() and strconv.Itoa isn't really a good idea but I am having issues trying to really grasp what it's all about. I understand there could be some inconsistencies during the conversion process but I am unable to grasp why such inconsistency could happen. I'll really appreciate it if some can explain to me like I am 5. A sample of what I am referring to can be seen below. Thanks
var amt int64 = 90 strconv.Itoa(int(amt))
strconv.Itoa() expects a value of type int, so you have to give it that:
log.Println("The amount is: " + strconv.Itoa(int(charge.Amount)))
But know that this may lose precision if int is 32-bit (while uint64 is 64), also sign-ness is different. strconv.FormatUint() would be better as that expects a value of type uint64:
log.Println("The amount is: " + strconv.FormatUint(charge.Amount, 10))
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 int nor to string, use one of these:
log.Println("The amount is:", charge.Amount)
log.Printf("The amount is: %d\n", charge.Amount)
if you want to convert int64 to string, you can use :
strconv.FormatInt(time.Now().Unix(), 10)
or
strconv.FormatUint
Use the strconv package's Itoa function.
For example:
package main
import (
"strconv"
"fmt"
)
func main() {
t := strconv.Itoa(123)
fmt.Println(t)
}
fmt.Sprintf("%v",value);
If you know the specific type of value use the corresponding formatter for example %d for int
More info - fmt