Wednesday, October 16, 2013

sigfigs

def _sigfigs(n, sigfigs=3):
    'helper function to round a number to significant figures'
    if n == 0 or math.isnan(n):  # avoid math domain errors
        return n
    return round(float(n), -int(math.floor(math.log10(abs(n))) - sigfigs + 1))

1 comment:

  1. Quickly, you can use your Lotto ticket (purchased from first October) to recuperate a tax car calculator towards fun stuff near you.

    ReplyDelete