golang超大数字计算
package mainfunc main() {
numstr := "360000000000000000000000000000"
fmt.Println(BigIntAdd(numstr, 99))
fmt.Println(BigIntReduce(numstr, 99))
}
func BigIntAdd(numstr string, num int64) string {
n, _ := new(big.Int).SetString(numstr, 10)
m := new(big.Int)
m.SetInt64(num)
m.Add(n, m)
return m.String()
}
func BigIntReduce(numstr string, num int64) string {
n, _ := new(big.Int).SetString(numstr, 10)
m := new(big.Int)
m.SetInt64(-num)
m.Add(n, m)
return m.String()
}
以上是 golang超大数字计算 的全部内容, 来源链接: utcz.com/z/512440.html