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
+6.5k PHP : Proper way to get UTF-8 character or string length
+9.6k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+18.5k Golang : How to get hour, minute, second from time?
+19.9k Golang : Append content to a file
+20.3k Golang : Count number of digits from given integer value
+6.9k Swift : substringWithRange() function example
+31.7k Golang : bufio.NewReader.ReadLine to read file line by line
+6.3k Golang : Get missing location after unmarshal binary and gob decode time.
+8.9k Golang : HTTP Routing with Goji example
+5.9k Javascript : How to replace HTML inside <div>?
+22.3k Golang : Securing password with salt