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
+31.8k Golang : Copy directory - including sub-directories and files
+7.9k Golang : Check if integer is power of four example
+19.4k Golang : How to run your code only once with sync.Once object
+5.8k Golang : Convert Chinese UTF8 characters to Pin Yin
+18.2k Golang : Implement getters and setters
+10.3k Golang : How to delete element(data) from map ?
+16.1k Golang : Send email and SMTP configuration example
+10.3k Golang : Flip coin example
+32.2k Golang : Regular Expression for alphanumeric and underscore
+20.1k Golang : Secure(TLS) connection between server and client
+6.7k Golang : Get Alexa ranking data example