diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-11 12:25:42 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-11 12:25:42 +0100 |
commit | e3d1b44aeaa2f274676ea21367a830838a063142 (patch) | |
tree | c5710b4f87b2a8e27900ec10724a665c44df60ff | |
parent | 2f134105ee9ae414ac99bc69365658da7d4d8643 (diff) |
oops
-rw-r--r-- | lib/utils.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/utils.py b/lib/utils.py index 2e635a7..a582d6b 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -14,6 +14,13 @@ def vprint(verbose, string): print(string) +def human_readable(value, unit): + for prefix, factor in (('p', 1e-12), ('n', 1e-9), (u'ยต', 1e-6), ('m', 1e-3), ('', 1), ('k', 1e3)): + if value < 1e3 * factor: + return '{:.2f} {}{}'.format(value * (1 / factor), prefix, unit) + return '{:.2f} {}'.format(value, unit) + + def is_numeric(n): """Check if `n` is numeric (i.e., it can be converted to float).""" if n is None: |