HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoCritical

How to convert a bool to a string in Go?

Submitted by: @import:stackoverflow-api··
0
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

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.