In this section, we're going to learn how to convert integer and float values into string values. At first, this may seem a little complex, but after this section you will feel comfortable enough to work with those conversions. So let's go back to our editor and see how we can do it.
Let's start with converting an integer value into a string value:
- Under the string conversion package, which is
strconv
, we have a bunch of functions that we can use for these conversions; one of these functions isFormatInt
. - So let's go ahead and use base 10. You can have different bases, such as 16, 10, and 24.
- If you look at the signature, you'll see that it returns a string.
- Now, the code will not work exactly the way we want, but we're going to see why and we're going to fix it. The following output is obtained when you run the code that has been previously described: