I need to convert an uint32
to string
. How can I do that? strconv.Itoa
doesn't seem to work.
Long story:
I need to convert an UID received through the imap package to string
so that I can set it later as a sequence. As a side note I'm wondering why such conversions are difficult in Go. A cast string(t)
could have been so much easier.
The UInt32 value type represents unsigned integers with values ranging from 0 to 4,294,967,295. UInt32 provides methods to compare instances of this type, convert the value of an instance to its String representation, and convert the String representation of a number to an instance of this type.
I would do this using strconv.FormatUint
:
import "strconv" var u uint32 = 17 var s = strconv.FormatUint(uint64(u), 10) // "17"
Note that the expected parameter is uint64
, so you have to cast your uint32
first. There is no specific FormatUint32
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With