[Git][NTPsec/ntpsec][decimal-fix] Rearranged ifs.
Ian Bruene
gitlab at mg.gitlab.com
Thu Apr 13 23:39:33 UTC 2017
Ian Bruene pushed to branch decimal-fix at NTPsec / ntpsec
Commits:
52529a02 by Ian Bruene at 2017-04-13T18:38:37-05:00
Rearranged ifs.
- - - - -
1 changed file:
- pylib/util.py
Changes:
=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -332,22 +332,22 @@ def fitinfield(value, fieldsize):
pad = " " * (fieldsize - vallen)
newvalue = pad + value
else: # Insufficient room, round as few digits as possible
- diff = vallen - fieldsize
- if "." in value:
+ if "." in value: # Ok, we *do* have decimals to crop
+ diff = vallen - fieldsize
declen = len(value.split(".")[1]) # length of decimals
- else:
- declen = 0
- croplen = min(declen, diff) # Never round above the decimal point
- roundlen = declen - croplen # How many digits we round to
- newvalue = str(round(float(value), roundlen))
- splitted = newvalue.split(".") # If this fails something went wrong
- declen = len(splitted[1])
- if roundlen == 0: # if rounding all the decimals don't display .0
- # but do display the point, to show that there is more beyond
- newvalue = splitted[0] + "."
- elif roundlen > declen: # some zeros have been cropped, fix that
- padcount = roundlen - declen
- newvalue = newvalue + ("0" * padcount)
+ croplen = min(declen, diff) # Never round above the decimal point
+ roundlen = declen - croplen # How many digits we round to
+ newvalue = str(round(float(value), roundlen))
+ splitted = newvalue.split(".") # This should never fail
+ declen = len(splitted[1])
+ if roundlen == 0: # if rounding all the decimals don't display .0
+ # but do display the point, to show that there is more beyond
+ newvalue = splitted[0] + "."
+ elif roundlen > declen: # some zeros have been cropped, fix that
+ padcount = roundlen - declen
+ newvalue = newvalue + ("0" * padcount)
+ else: # No decimals, nothing we can crop
+ newvalue = value
return newvalue
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/52529a0256ce515474ec628eeeae6f9465e2fd6a
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/52529a0256ce515474ec628eeeae6f9465e2fd6a
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170413/db502535/attachment.html>
More information about the vc
mailing list