diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2018-03-30 20:50:04 +0200 |
---|---|---|
committer | Marcus Müller <marcus.mueller@ettus.com> | 2018-03-30 20:50:04 +0200 |
commit | 61c0382eb2935a6da6c81bd93c8b9c8ef2893df2 (patch) | |
tree | 5e67df4059f5522ccc62cd85f33100ee96bb7988 /gnuradio-runtime/python/gnuradio/eng_notation.py | |
parent | 9a6bf484394f5954483477856f6a6712331b9ee6 (diff) | |
parent | 20d463d138782fd56397f5324be6e34af156b239 (diff) |
Merge branch 'maint' through 'last_merge_to_master'
This is the last time we're merging 'maint' to 'master'. The 'maint'
branch will cease to exist shortly; we'll have a 'maint-3.7' branch.
For further information on the new development model:
http://lists.gnu.org/archive/html/discuss-gnuradio/2018-02/msg00133.html
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/eng_notation.py')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_notation.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py index d23f9005f0..12332aef7d 100644 --- a/gnuradio-runtime/python/gnuradio/eng_notation.py +++ b/gnuradio-runtime/python/gnuradio/eng_notation.py @@ -36,29 +36,30 @@ scale_factor['p'] = 1e-12 scale_factor['f'] = 1e-15 scale_factor['a'] = 1e-18 -def num_to_str (n): +def num_to_str (n, precision=6): '''Convert a number to a string in engineering notation. E.g., 5e-9 -> 5n''' m = abs(n) + format_spec = '%.' + repr(int(precision)) + 'g' if m >= 1e9: - return "%gG" % (n * 1e-9) + return '%sG' % float(format_spec % (n * 1e-9)) elif m >= 1e6: - return "%gM" % (n * 1e-6) + return '%sM' % float(format_spec % (n * 1e-6)) elif m >= 1e3: - return "%gk" % (n * 1e-3) + return '%sk' % float(format_spec % (n * 1e-3)) elif m >= 1: - return "%g" % (n) + return '%s' % float(format_spec % (n)) elif m >= 1e-3: - return "%gm" % (n * 1e3) + return '%sm' % float(format_spec % (n * 1e3)) elif m >= 1e-6: - return "%gu" % (n * 1e6) # where's that mu when you need it (unicode?) + return '%su' % float(format_spec % (n * 1e6)) elif m >= 1e-9: - return "%gn" % (n * 1e9) + return '%sn' % float(format_spec % (n * 1e9)) elif m >= 1e-12: - return "%gp" % (n * 1e12) + return '%sp' % float(format_spec % (n * 1e12)) elif m >= 1e-15: - return "%gf" % (n * 1e15) + return '%sf' % float(format_spec % (n * 1e15)) else: - return "%g" % (n) + return '%s' % float(format_spec % (n)) def str_to_num (value): |