Golang : Find the length of big.Int variable example
There is a chance that you will ever need to get the length of big.Int
variable and below is a simple example on how to count the length of a big.Int
variable.
package main
import (
"fmt"
"math/big"
)
func main() {
// base 10
bigInteger := new(big.Int)
bigInteger.SetString("100000000000000000L", 10) //18
fmt.Println("Value : ", bigInteger)
fmt.Println("Length : ", len(bigInteger.Text(10)))
}
Output:
Value : 100000000000000000
Length : 18
Reference:
https://www.socketloop.com/tutorials/golang-convert-string-or-integer-to-big-int-type
See also : Golang : Calculate Relative Strength Index(RSI) example
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
+14.9k Golang : convert string or integer to big.Int type
+10.6k Golang : Convert(cast) float to int
+18.2k Golang : Example for DSA(Digital Signature Algorithm) package functions
+11.7k Golang : Convert(cast) uintptr to string example
+4.3k Responsive Google Adsense
+11.3k Golang : Remove or trim extra comma from CSV
+17.2k Golang : Generate thumbnails from images
+3.1k Golang : PGX CopyFrom to insert rows into Postgres database
+8.1k Golang : Timeout example
+9.6k Golang : Get local time and equivalent time in different time zone
+27.8k Golang : How to create new XML file ?