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
+7.3k Golang : File path independent of Operating System
+12.4k Golang : Find files by name - cross platform example
+1.1k Golang : Executing and evaluating nested loop in html template
+32k Golang : How to read CSV file
+7.5k Golang : How to implement two-factor authentication?
+4.7k Yum Error: no such table: packages
+2k Javascript : Put image into Chrome browser's console
+2.3k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+2.5k PHP : Convert CSV to JSON with YQL example
+9.7k Swift : Convert (cast) Int to String ?
+2.5k Restart Apache or Nginx web server without password prompt