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
go - Golang converting string to int64 - Stack Overflow
GMS "unable to convert string "" to int64" Error, Not Trying to convert Anything
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
Parsing string into int64 example:
// Use the max value for signed 64 integer. http://golang.org/pkg/builtin/#int64
var s string = "9223372036854775807"
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
panic(err)
}
fmt.Printf("Hello, %v with type %s!\n", i, reflect.TypeOf(i))
output:
Hello, 9223372036854775807 with type int64!
https://play.golang.org/p/XOKkE6WWer
No, there's no Atoi64. You should also pass in the 64 as the last parameter to ParseInt, or it might not produce the expected value on a 32-bit system.
var s string = "9223372036854775807"
i, _ := strconv.ParseInt(s, 10, 64)
fmt.Printf("val: %v ; type: %[1]T\n", i)
https://play.golang.org/p/FUC8QO0-lYn