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
+4k Linux/Unix : Commands that you need to be careful about
+4.6k Golang : How to stop user from directly running an executable file?
+4.9k Golang : Get final or effective URL with Request.URL example
+6.4k Golang : Inject/embed Javascript before sending out to browser example
+15.1k Golang : Example for DSA(Digital Signature Algorithm) package functions
+5.5k Golang : Randomize letters from a string example
+4.5k Fix sudo yum hang problem with no output or error messages
+24.6k Golang : JQuery AJAX post data to server and send data back to client example
+11.2k Golang : How to shuffle elements in array or slice?
+2.4k Javascript : Detect when console is activated and do something about it
+6.3k Android Studio : Checkbox for user to select options example
+18.1k Golang : Setting up/configure AWS credentials with official aws-sdk-go