Golang : convert string or integer to big.Int type
Problem :
You have a big integer number in string format and you want to convert(cast) it to big.Int type. How to do that?
Solution :
Use math/big.Int
type. Create a new big.Int type variable and the set the value with SetString()
method.
For example :
// convert number to big.Int type
ip := new(big.Int)
ip.SetString("338288524927261089654163772891438416681", 10) //base 10
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.1k Golang : micron to centimeter example
+11.6k Golang : Pass database connection to function called from another package and HTTP Handler
+10k How to test Facebook App on localhost ?
+11.2k Golang : Listen and Serve on sub domain example
+4.5k Golang : fmt.Println prints out empty data from struct
+3.7k MariaDB/MySQL : How to get version information
+14.2k Golang : Get checkbox or extract multipart form data value example
+14.9k Golang : Read integer from file into array
+28k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+36k Golang : Read a text file and replace certain words
+5.9k Swift : substringWithRange() function example