paint-brush
Converting Strings To Integers And Integers To Stringsby@harrison_brock

Converting Strings To Integers And Integers To Strings

by Harrison BrockDecember 18th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Converting Strings to Integers or Integers to Strings is a common task that developers face every day. The Go Standard Library comes with packages to make this task easier. Go developers need to know to use the standard library and when to look for third-party libraries to solve a task.

People Mentioned

Mention Thumbnail
featured image - Converting Strings To Integers And Integers To Strings
Harrison Brock HackerNoon profile picture

Converting Strings to Integers or Integers to Strings is a common task that developers face every day. The Go Standard Library comes with packages to make this task easier. Go developers need to know to use the standard library and when to look for third-party libraries to solve a task.

Convert A String To An Integer

To convert a string to an integer, we will use the function Atio from the strconv package. This function handles converting the string to an integer for us. Below is a code example of how to do this.

<a href="https://medium.com/media/7fab51c97f6392b60a92257cad913101/href">https://medium.com/media/7fab51c97f6392b60a92257cad913101/href</a>

When we run this program, we will see this output::

This tells us that the value is 747 and the data type of int.

Convert A Integer To An String

To convert an integer to a string, we will use the function the Itoa from the strconv package. This function handles converting the integer to a string for us. Below is a code example of how to do this.

<a href="https://medium.com/media/6289f8080d9601c6c3aee7a3f9594860/href">https://medium.com/media/6289f8080d9601c6c3aee7a3f9594860/href</a>

When we run this program, we will see this output:

Int to String

This tells us that the value is 747 and the data type of string.

Originally published at harrisonbrock.com