Next / Previous / Contents / TCC Help System / NM Tech homepage

58. statNumber(): Display a float without too much precision

There is no point in displaying a mean value of several thousand with two digits after the decimal. Hence, this function formats a float without quite so much precision.

cbchistlib.py
# - - -   s t a t N u m b e r

def statNumber(x):
    '''Display x without too much precision.
    '''
    if x > 100.0:  format = '%.0f'
    elif x > 10.0: format = '%.1f'
    else:          format = '%.2f'

    return format % x