Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function to count digits in a number in golang
package main
import (
"fmt"
)
func main() {
fmt.Println(CountDigits(1234454666))
}
func CountDigits(i int64) (count int64) {
for i > 0 {
i = i / 10
count++
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.