Check in awk about a value of variable

I need to check if a variable have numeric value and if yes how many digits does it have, how do i do it?

#
# return number of digits if str is all digits
# otherwise return 0
#
function countdigits( str )
{
   digits = 0
   len = split( str, a ,"" )
   for ( i = 1; i <= len; i++ )
       if (( a + 0 ) == a )
          digits++

   if ( len == digits )
      return digits
   else
      return 0
}

Something like this?

awk 'int(var) == var {print length(var)}'

Regards

I added the "nope" to make it easier to see the output.

> echo 159a | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope
> echo 159a1 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope
> echo 1591 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
4
> echo a1591 | awk '{ink2=ink=$0;lenx=length(ink); gsub("[:alpha:]","",ink2); leny=length(ink2); if (lenx==leny){print lenx}else{print "nope"}}'
nope