[Git][NTPsec/ntpsec][wip-ntpq-peers-display] Fixed f8unit formating.
Ian Bruene
gitlab at mg.gitlab.com
Fri Mar 24 22:41:09 UTC 2017
Ian Bruene pushed to branch wip-ntpq-peers-display at NTPsec / ntpsec
Commits:
14b26a77 by Ian Bruene at 2017-03-24T17:37:05-05:00
Fixed f8unit formating.
f8unit now correctly formats zero values. "Shouldn't be possible" indeed...
f8unit will now print an integer if the passed value does not have any
decimal places. This takes care of the N.something nanoseconds problem.
f8unit no longer prints a sign on positive numbers.
- - - - -
1 changed file:
- pylib/util.py
Changes:
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -93,15 +93,17 @@ def f8unit(f, startingunit, strip=False):
try:
unit = UNITS[startingunit + unitsmoved]
except IndexError: # out of defined units revert to original, very ugly
- rendered = ("%+6f" % oldf) + UNITS[startingunit] # but few options
- if abs(f) >= 100.0: # +xxx.x
- rendered = ("%+6.1f" % f) + unit
+ rendered = ("%6f" % oldf) + UNITS[startingunit] # but few options
+ if abs(f).is_integer():
+ rendered = ("%6d" % f) + unit
+ elif abs(f) >= 100.0: # +xxx.x
+ rendered = ("%6.1f" % f) + unit
elif abs(f) >= 10.0: # +xx.xx
- rendered = ("%+6.2f" % f) + unit
+ rendered = ("%6.2f" % f) + unit
elif abs(f) >= 1.0: # +x.xxx
- rendered = ("%+6.3f" % f) + unit
- else: # should not be possible
- rendered = ("%8f" % oldf)
+ rendered = ("%6.3f" % f) + unit
+ else: # zero, if it weren't then scaleforunit would have moved it up
+ rendered = ("%6.3f" % oldf) + unit
if strip:
return rendered.lstrip().rstrip()
return rendered
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/14b26a777fc4a5184128d84917edf626dbaaa261
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170324/287d5d63/attachment.html>
More information about the vc
mailing list