snippetgoCritical
How to convert a bool to a string in Go?
Viewed 0 times
stringconverthowbool
Problem
I am trying to convert a
bool called isExist to a string (true or false) by using string(isExist) but it does not work. What is the idiomatic way to do this in Go?Solution
use the strconv package
docs
func FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b
docs
strconv.FormatBool(v)func FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b
Context
Stack Overflow Q#38552803, score: 306
Revisions (0)
No revisions yet.