To convert a boolean value to a string in Go using the strconv.FormatBool()
function, you can follow these steps:
import "strconv"
var b bool = true
strconv.FormatBool()
function to convert the boolean variable to a string:str := strconv.FormatBool(b)
The strconv.FormatBool()
function returns a string representation of the boolean value. In this example, the variable str
will contain the string "true".
Here's a complete example:
package main
import (
"fmt"
"strconv"
)
func main() {
var b bool = true
str := strconv.FormatBool(b)
fmt.Println(str)
}
Output:
true