To golang bool to string (also searched as bool to string golang, golang convert bool to string, go bool to string, or boolean to string golang), use strconv.FormatBool for the clearest API, or fmt.Sprintf when you are already formatting a larger message (golang sprintf bool with the %t verb). The reverse—golang string to bool—uses strconv.ParseBool. You cannot compare a bool to the string "true" without converting one side; see string comparison in Go after both sides are strings. For format verbs in general, see string interpolation in Go; for variable types and scope.
Tested with Go 1.24 on Linux.
%t prints booleans; %v uses the default format for any type. Prefer FormatBool when the value is only a bool.
strconv.FormatBool (preferred)
func FormatBool(b bool) string returns "true" or "false":
package main
import (
"fmt"
"strconv"
)
func main() {
v := true
s := strconv.FormatBool(v)
fmt.Printf("%T %v\n", v, v)
fmt.Printf("%T %q\n", s, s)
}You should see bool true then string "true".
fmt.Sprintf — golang sprintf bool
Use %t for booleans; %v also works but is less explicit when the argument list mixes types:
package main
import "fmt"
func main() {
b := false
fmt.Println(fmt.Sprintf("%t", b))
fmt.Println(fmt.Sprintf("enabled=%v", true))
}You should see false then enabled=true.
golang string to bool with ParseBool
strconv.ParseBool accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False (see docs):
package main
import (
"fmt"
"strconv"
)
func main() {
for _, s := range []string{"true", "0", "maybe"} {
v, err := strconv.ParseBool(s)
fmt.Println(s, v, err)
}
}You should see true true <nil>, 0 false <nil>, and a non-nil error for maybe.
Do not compare bool to a string literal
This does not compile:
var v bool = true
if v == "true" { } // invalid operation: bool == untyped stringConvert with FormatBool / ParseBool or compare two strings after conversion.
Summary
For convert bool to string golang and go convert bool to string, strconv.FormatBool is the smallest and fastest option; fmt.Sprintf("%t", b) covers golang sprintf bool when building larger messages. For golang string to bool, use strconv.ParseBool and handle errors. That keeps logs, flags, and JSON-adjacent text consistent without illegal bool vs string comparisons.
References
- strconv.FormatBool
- strconv.ParseBool
- fmt.Sprintf
Frequently Asked Questions
What is the best way to golang convert bool to string?
Prefer strconv.FormatBool(b); it always returns exactly "true" or "false" in English lowercase and avoids format-string mistakes.
How does golang sprintf bool work?
Use fmt.Sprintf with %t for boolean text or %v for the default true/false representation; strconv.FormatBool is clearer when the value is always a bool.
How do I golang string to bool from user input?
Use strconv.ParseBool(s) which accepts true false 0 1 t f and case-insensitive variants, and always check the error for invalid input.
Why does my code fail on v == "true" with a bool v?
Go does not compare bool to string directly; parse the string with ParseBool or convert the bool with FormatBool before comparing strings.
Is FormatBool faster than Sprintf for booleans?
Yes; FormatBool avoids the general formatter and allocates less, which matters in hot loops but rarely dominates in normal code.

