Calculate the magitude of your number, and adjust the value of precision accordingly.
The maginitude here is a basically the value of n in 10^n, like you use for scientific notation. In your examples, that would be 1, 2 and 0 repectively: the largest value of n where the result of 10^n is smaller than the number you working with. In your case, it seems you want to precision to be n+2.
There are several ways to calculate the magnitude. Mathematically, it is simply 10Log(x), but depending on the range you are interested in and the performance you need, a simple loop dividing by 10 or even a big if/else if construct or something like that may be enough for your needs.