def order_of_magnitude(x):
    """Returns the nearest power of 10 less than x
    x = 0.00345, returns -3, x = 4320.0 returns 3.
    x = 5.42e+25, returns 25
    """
    stringx = str(float(x))

    # if x is in e form, just return the e multiplier
    eindex = stringx.find('e')
    if not eindex == -1:
        return(int(stringx[eindex+2:]))

    
    point_index = stringx.find('.')
    count = 0
    triggered = 0
    while True:
        #If number is like 0.0032, we skip 0s, count goes up to 4 then breaks
        if stringx[count] == '0':
            count += 1
            continue
        #For point_index - count - 1 to still work, aka 1-4-1 = -4 to be correct, 
        elif stringx[count] == '.':
            count += 1
            triggered = 1
            continue
        # If is a number like 423.55, immediately break, count is still 0, return point_index - count - 1, so here
        # It would be 2
        else:
            break
    
    return(point_index - count - 1 + triggered)