def float_nsf(q, n):
    """
    Truncate a float to n significant figures.  May produce overflow in 
    very last decimal place when q < 1.  This can be removed by an extra 
    formatted print. 
    Arguments:
      q : a float
      n : desired number of significant figures
    Returns:
    Float with only n s.f. and trailing zeros, but with a possible small overflow.
    """
sgn = npy.sign(q)
q = abs(q)
n = int(npy.log10(q / 10.0))
if q < 1.0:
    val = q / 10 ** (n - 1)
else:
    val = q / 10 ** n
return sgn * int(val) * 10.0 ** n
How can I print many significant figures in Python?