We're going to start off with learning how to convert a Boolean
value into a String
value:
- In our editor, after creating a new file,
main.go
, and themain
function, as always, let's consider a variable calledisNew
, which is a Boolean. Hence the value will betrue
.
- So, let's say that we want to print it out to our console with a message. Check the following screenshot:
As you can see, we encounter a compile-time error. Thus, you cannot use the +
operator and we need to convert the isNew
Boolean value to its string representation.
- Let's use the
stringconvert
package, which has various string conversion functions, of which, we're going to useFormatBool
. - Taking a
Boolean
value returns every string representation of it, and in this case, it'sisNew
. If you look at the signature, you'll see that it returns true or false based on the value of the Boolean value passed:
- So, let's add
isNewStr
, run it and check the output:
There is another way of printing such values...