DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to convert an int type value to a uint type value in Go or Golang?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to convert an int type value to a uint type value in Go or Golang?

#go

Originally posted here!

To convert an int type value to a uint type value in Go or Golang, you can use the built-in uint() function and pass the int type value as an argument to the function. The function returns the value as the uint type.

For example, let's say we need to convert an int type value of 3000 to a uint type.

To do that we can use the uint() built-in function and pass the value of 3000 as an argument to the function like this,

package main

import "fmt"

func main() {
    // a `int` type value
    intNum := 3000

    // convert the `int` type value of 3000
    // to `uint` type value using the
    // `uint()` built-in method
    uintNum := uint(intNum)

    // log to the console
    fmt.Println(uintNum) // `3000` and the type is `uint`
}
Enter fullscreen mode Exit fullscreen mode

As you can see from the above code we have converted the int type value of 3000 to a uint type value. Yay ๐Ÿฅณ!

See the above code live in The Go Playground.

That's all ๐Ÿ˜ƒ.

Feel free to share if you found this useful ๐Ÿ˜ƒ.


Top comments (0)

๐ŸŒš Friends don't let friends browse without dark mode.

Sorry, it's true.