如何将长十六进制字符串解析为uint

I'm pulling in data that is in long hexadecimal string form which I need to convert into decimal notation, truncate 18 decimal places, and then serve up in JSON.

For example I may have the hex string:

"0x00000000000000000000000000000000000000000000d3c21bcecceda1000000"

At first I was attempting to use ParseUint(), however since the highest it supports is int64, my number ends up being way too big.

This example after conversion and truncation results in 10^6. However there are instances where this number can be up to 10^12 (meaning pre truncation 10^30!).

What is the best strategy to attack this?

Use math/big for working with numbers larger than 64 bits.

From the Int.SetString example:

s := "d3c21bcecceda1000000"
i := new(big.Int)
i.SetString(s, 16)
fmt.Println(i)

https://play.golang.org/p/vf31ce93vA

The math/big types also support the encoding.TextMarshaler and fmt.Scanner interfaces.

For example

i := new(big.Int)
fmt.Sscan("0x000000d3c21bcecceda1000000", i)

Or

i := new(big.Int)
fmt.Sscanf("0x000000d3c21bcecceda1000000", "0x%x", i)