Faster way to shift a decimal in Python to remove zeros?
Question: I have a variety of numbers that are always bounded by 0 and 1. The numbers
range in value such as

    
    
    .9, .08, .00024, .00000507
    

My goal is to convert these numbers to the following

    
    
    .9, .8, .24, .507
    

That is, I want to remove any zeros after the decimal point.

I have the following code to do this. Is there a way to do this faster in
terms of performance?

    
    
    import math
    x=.009
    n = int(-math.log10(x))
    x *= math.pow(10, n)
    


Answer: Faster method of doing it (gets faster with larger numbers):

    
    
    def method2(x):
        while x < 0.1:
            x *= 10
        return x
    

Even faster:

    
    
    def method3(x):
        while x < 0.01:
            x *= 100
        while x < 0.1:
            x *= 10
        return x
    

Funny method of doing it (slower than the question):

    
    
    def remove_zeros(a):
        return float("0." + str(long(str(1+a)[2:])))
    

