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
+13.9k Golang : Get dimension(width and height) of image file
+5.8k Golang : List all packages and search for certain package
+9.1k Golang : Handle sub domain with Gin
+10.3k Golang : How to check if a website is served via HTTPS
+8.5k Linux/Unix : fatal: the Postfix mail system is already running
+3.7k Golang : Switch Redis database redis.NewClient
+7.3k Golang : Calculate how many weeks left to go in a given year
+19.6k Golang : Close channel after ticker stopped example
+10.9k Golang : Natural string sorting example
+24.5k Golang : Time slice or date sort and reverse sort example
+4.9k Nginx and PageSpeed build from source CentOS example
+12.3k Golang : 2 dimensional array example