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
+45.7k Golang : Read tab delimited file with encoding/csv package
+24.2k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+13.6k Golang : unknown escape sequence error
+41.2k Golang : Convert string to array/slice
+5.6k Golang : Find change in a combination of coins example
+4.4k JavaScript : Rounding number to decimal formats to display currency
+36.2k Golang : Converting a negative number to positive number
+9.9k Golang : Compare files modify date example
+35.6k Golang : Get file last modified date and time
+21.7k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+20.5k Golang : Underscore or snake_case to camel case example
+9.4k Golang : Sort and reverse sort a slice of floats