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
+14k Golang : convert rune to unicode hexadecimal value and back to rune character
+7.4k Golang : Individual and total number of words counter example
+10.5k Golang : Meaning of omitempty in struct's field tag
+8.7k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+4.2k Javascript : Empty an array example
+22.4k Golang : Read directory content with filepath.Walk()
+10.7k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+14.7k Golang : Reset buffer example
+13.5k Golang : Get constant name from value
+15.7k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+13.9k Golang : unknown escape sequence error
+10.3k Golang : How to profile or log time spend on execution?