O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The dominant function in the preceding sample code is the ParseInt function of package strconv. The function is called with three arguments: input, the base of input, and bit size. The base determines how the number is parsed. Note that the hexadecimal has the base (second argument) of 16 and the binary has the base of 2. The function Atoi of package strconv is, in fact, the ParseInt function with the base of 10.

The  ParseFloat function converts the string to a floating-point number. The second argument is the precision of bitSizebitSize = 64 will result in float64bitSize = 32 will result in float64, but it is convertible to float32 without changing its value. 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required