Golang : Convert(cast) bigint to string




Problem :

You want to convert(cast) a big integer value to string for display.

Solution :

Use big.Int.String() function to convert the big integer value to string. For example :

 package main

 import (
 "fmt"
 "math/big"
 )

 func main() {
 bigInt := big.NewInt(123456789)
 bigStr := bigInt.String()

 fmt.Println(bigStr)
 }

Reference :

http://golang.org/pkg/math/big/#Int.String





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