log() can be used to extract the number of digits from a number. log(100) = 2, log(1000) = 3, and log(108) = 2.033...

So you can use rounddown(log(<number>)) with a series of nested if statements...