In my opinion the "length" of a number can only be the length of the string generated when converting this number to a string with the default string conversion.
Note that keys in tables are not necessarily integers, they can be any number. It is an integer only to restrict tables to their sequence, but not all tables have a unique sequence, if there are "holes" such that there exists a integer key k in table t, where k >= 2, t[k] is not null, and t[k-1] is null).
Codes that expect sequences to give a meaning to "#t" cannot be portable if t is not a sequence with no holes. But there's no easy builtin properties of tables that can assert it forms a unique predictable sequence (note that the presence of non-integer keys in the table does not invalidate a sequence: a table is a valid sequence depending only on the subset of its keys that are integers, and keys below 1 are ignored: you can safely add a key 0 or -1 to any table that is a sequence without invalidating the sequence and what #t will return).
This behavior of tables in Lua and the very weak definition of "sequences" is very tricky.