Project

General

Profile

« Previous | Next » 

Revision 980

util.py: Added basic to_si() to add SI prefix to value

View differences:

lib/util.py
41 41
    if val >= 1: sig_figs += 1
42 42
    return format_str('%#.'+str(sig_figs)+'g', val*100)+'%'
43 43

  
44
def to_si(val, sig_figs=3):
45
    '''Adds SI prefix to value'''
46
    prefix = ''
47
    if val < 1: prefix = 'm'; val *= 1000
48
    return format_str('%#.'+str(sig_figs)+'g', val)+' '+prefix
49

  
44 50
#### Iterables
45 51

  
46 52
def first(iter_): return iter_.next()

Also available in: Unified diff