How to get length of a number in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

To get length of a number, convert integer to string using strconv.Itoa() method then use len() method it will count and return number of integer elements.

In golang the len() method used for counts elements.

Let’s start

package main
import (
  "fmt"
  "strconv"
)

func main() {
  num := 847883663;
	fmt.Println("Length of number", len(strconv.Itoa(num)))
}

In the above program, we are accessing length of number, let’s see the output.

Output:

Length of number 9

Try it yourself

All the best 👍