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
+5.7k Golang : Convert(cast) uintptr to string example
+5.8k Golang : Get terminal width and height example
+7.6k Golang : How to implement two-factor authentication?
+12.7k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+2.3k Golang : Capture text return from exec function example
+2.6k Golang : Return multiple values from function
+2.6k AWS S3 : Prevent Hotlinking policy
+7.1k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+5.2k Golang : Pass database connection to function called from another package and HTTP Handler
+4.8k Golang : Populate or initialize struct with values example
+1.7k Adding Skype actions such as call and chat into web page examples