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
+9.4k Golang : Fix go.exe is not compatible with the version of Windows you're running
+5k Linux/MacOSX : Search for files by filename and extension with find command
+27.7k Golang : How to create new XML file ?
+15.7k Golang : XML to JSON example
+32.5k Golang : Proper way to set function argument default value
+6.6k Golang : Ways to recover memory during run time.
+31.7k Golang : Converting a negative number to positive number
+42.4k Golang : Use wildcard patterns with filepath.Glob() example
+5.6k PHP : Shuffle to display different content or advertisement
+4.9k Golang : Shuffle array of list
+9.8k Golang : Natural string sorting example
+7.4k Golang : How to capture return values from goroutines?