Golang : Convert(cast) int64 to string
Problem :
You want to convert(cast) a big integer value to string for display.
Solution :
Use strconv.FormatInt() function to convert the int64 value to string. For example :
package main
import (
"fmt"
"strconv"
)
func main() {
var val int64 = 123456789
str := strconv.FormatInt(val, 10) // use base 10 for sanity purpose
fmt.Println(str) // int64 converted to string!
fmt.Printf("After conversion : %v \n", val) // alternate method works too!
}
Output :
123456789
After conversion : 123456789
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.3k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+8.2k Random number generation with crypto/rand in Go
+26.1k Golang : Record voice(audio) from microphone to .WAV file
+11.8k Android Studio : Password input and reveal password example
+20.8k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+4.8k Unix/Linux : How to test user agents blocked successfully ?
+7.7k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+4.7k Fix yum-complete-transaction error
+7.5k Golang : How to capture return values from goroutines?
+9.8k Golang : Web routing/multiplex example
+8.8k Golang : Test a slice of integers for odd and even numbers