use the strconv package
docs
strconv.FormatBool(v)
Answer from Brrrr on Stack Overflowfunc FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b
ZetCode
zetcode.com › golang › strconv-parsebool
Using strconv.ParseBool in Go
April 20, 2025 - The strconv.ParseBool function converts a string to a boolean value.
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
package main import ( "fmt" "strconv" ) func main() { i := 10 s := strconv.Itoa(i) fmt.Printf("%T, %v\n", s, s) } ... ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
Educative
educative.io › answers › how-to-use-the-strconvparsebool-function-in-golang
How to use the strconv.ParseBool() function in Golang
The ParseBool() function returns the value in the boolean form represented by the string that is provided. It belongs to a strconv package. It only accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, and False.
Dot Net Perls
dotnetperls.com › convert-string-bool-go
Go - Convert String to Bool: strconv.ParseBool - Dot Net Perls
May 24, 2021 - In Go we use the strconv package to convert types like bool and strings. We can use ParseBool to get a bool from a string.
IncludeHelp
includehelp.com › golang › strconv-parsebool-function-with-examples.aspx
Golang strconv.ParseBool() Function with Examples
September 7, 2021 - The ParseBool() function is an inbuilt function of the strconv package which is used to get the boolean value represented by the given string. The function accepts only 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value returns an error.
Go Packages
pkg.go.dev › github.com › go-playground › pkg › v5 › strconv
strconvext package - github.com/go-playground/pkg/v5/strconv - Go Packages
December 20, 2025 - ParseBool returns the boolean value represented by the string.
Top answer 1 of 4
306
use the strconv package
docs
strconv.FormatBool(v)
func FormatBool(b bool) string FormatBool returns "true" or "false"
according to the value of b
2 of 4
51
The two main options are:
strconv.FormatBool(bool) stringfmt.Sprintf(string, bool) stringwith the"%t"or"%v"formatters.
Note that strconv.FormatBool(...) is considerably faster than fmt.Sprintf(...) as demonstrated by the following benchmarks:
func Benchmark_StrconvFormatBool(b *testing.B) {
for i := 0; i < b.N; i++ {
strconv.FormatBool(true) // => "true"
strconv.FormatBool(false) // => "false"
}
}
func Benchmark_FmtSprintfT(b *testing.B) {
for i := 0; i < b.N; i++ {
fmt.Sprintf("%t", true) // => "true"
fmt.Sprintf("%t", false) // => "false"
}
}
func Benchmark_FmtSprintfV(b *testing.B) {
for i := 0; i < b.N; i++ {
fmt.Sprintf("%v", true) // => "true"
fmt.Sprintf("%v", false) // => "false"
}
}
Run as:
$ go test -bench=. ./boolstr_test.go
goos: darwin
goarch: amd64
Benchmark_StrconvFormatBool-8 2000000000 0.30 ns/op
Benchmark_FmtSprintfT-8 10000000 130 ns/op
Benchmark_FmtSprintfV-8 10000000 130 ns/op
PASS
ok command-line-arguments 3.531s
HotExamples
golang.hotexamples.com › examples › strconv › - › ParseBool › golang-parsebool-function-examples.html
Golang ParseBool Examples, strconv.ParseBool Golang Examples - HotExamples
// GetProfileSearchOptions fetches the options in the querystring that are being // used to filter and search for profiles func GetProfileSearchOptions(query url.Values) ProfileSearchOptions { so := ProfileSearchOptions{} if query.Get("top") != "" { inTop, err := strconv.ParseBool(query.Get("top")) if err == nil { so.OrderByCommentCount = inTop } } if query.Get("q") != "" { startsWith := strings.TrimLeft(query.Get("q"), "+@") if startsWith != "" { so.StartsWith = startsWith } } if query.Get("following") != "" { inFollowing, err := strconv.ParseBool(query.Get("following")) if err == nil { so.IsFollowing = inFollowing } } if query.Get("online") != "" { inFollowing, err := strconv.ParseBool(query.Get("online")) if err == nil { so.IsOnline = inFollowing } } return so }
7-Zip Documentation
documentation.help › Golang › strconv.htm
strconv - The Go Programming Language - Golang Documentation
ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
Gotd
ref.gotd.dev › pkg › strconv.html
Package: strconv
func ParseBool(str string) (bool, error) ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
gosamples
gosamples.dev › tutorials › convert string to bool in go
🔟 Convert string to bool in Go
September 30, 2021 - To convert a string to a bool in Go, use strconv.ParseBool() function from the strconv package. It takes one of the accepted string values: "1", "t", "T", "TRUE", "true", "True", "0", "f", "F", "FALSE", "false", "False" and converts it to the equivalent boolean value: true or false.
Melvin George
melvingeorge.me › blog › convert-boolean-string-type-value-to-bool-type-value-go-golang
How to convert a boolean string type value to a bool type value in Go or Golang? | MELVIN GEORGE
August 22, 2022 - package main // import `strconv` package import ( "fmt" "strconv" ) func main() { // convert `string` type value of "true" // using the `ParseBool()` method by passing // the value "true" as its argument convertedBoolVal, err := strconv.ParseBool("true") // check if any error happened if err != nil { fmt.Println(err.Error()) return } // log output of the `convertedBoolVal` // variable to the console fmt.Println(convertedBoolVal) // true and the type is bool ✅ }
Reintech
reintech.io › term › using-strconv-parsebool-function-go
Using strconv.ParseBool() Function in Go | Reintech media
The strconv.ParseBool() function in Go converts a string to a boolean value.
Admfactory
admfactory.com › home › how to convert a string to a boolean type in golang
How to convert a string to a boolean type in Golang | ADMFactory
If you need help how to install Golang check the references links. To convert a string into a boolean use the ParseBool method. It returns the boolean value represented by the string.
Go Packages
pkg.go.dev › cuelang.org › go › pkg › strconv
strconv package - cuelang.org/go/pkg/strconv - Go Packages
March 3, 2026 - ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.
Go
go.dev › play › p › E6nZ6B8P6V
Go Playground - The Go Programming Language
Common problems companies solve with Go · Stories about how and why companies use Go
UBC Computer Science
cs.ubc.ca › ~bestchai › teaching › cs416_2015w2 › go1.4.3-docs › pkg › strconv › index.html
strconv - The Go Programming Language
ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.