Hi there,
I am trying to convert the string to big.Int using the big.SetString
method for the following code, however, I got error.
package main
import (
"fmt"
"math/big"
"strings"
)
func main() {
var val = "100su"
if val[len(val)-2:] == "su" {
val = strings.TrimSuffix(val, "su")
fmt.Println(val)
if _, failed := new(big.Int).SetString(val, 10); failed {
fmt.Println("error")
return
}
fmt.Println("succeed")
return
}
}
The following is the output:
100
error
As epxected, the provided string is just a number, however, when trying to convert the number, it failed.
Any help if appreciated.
Best,
Shawn