diff --git a/eos/saveddata/boosterSideEffect.py b/eos/saveddata/boosterSideEffect.py index 5b468c91c..4fd83591c 100644 --- a/eos/saveddata/boosterSideEffect.py +++ b/eos/saveddata/boosterSideEffect.py @@ -21,6 +21,9 @@ from logbook import Logger from sqlalchemy.orm import reconstructor +from eos.utils.round import roundToPrec + + pyfalog = Logger(__name__) @@ -56,9 +59,8 @@ class BoosterSideEffect: @property def name(self): return "{0}% {1}".format( - self.booster.getModifiedItemAttr(self.attr), - self.__effect.getattr('displayName') or self.__effect.name, - ) + roundToPrec(self.booster.getModifiedItemAttr(self.attr), 5), + self.__effect.getattr('displayName') or self.__effect.name) @property def attr(self): diff --git a/eos/utils/round.py b/eos/utils/round.py new file mode 100644 index 000000000..fe55f2e11 --- /dev/null +++ b/eos/utils/round.py @@ -0,0 +1,27 @@ +import math + + +def roundToPrec(val, prec, nsValue=None): + """ + nsValue: custom value which should be used to determine normalization shift + """ + # We're not rounding integers anyway + # Also make sure that we do not ask to calculate logarithm of zero + if int(val) == val: + return int(val) + roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1) + # But we don't want to round integers + if roundFactor < 0: + roundFactor = 0 + # Do actual rounding + val = round(val, roundFactor) + # Make sure numbers with .0 part designating float don't get through + if int(val) == val: + val = int(val) + return val + + +def roundDec(val, prec): + if int(val) == val: + return int(val) + return round(val, prec) diff --git a/gui/utils/numberFormatter.py b/gui/utils/numberFormatter.py index 617e9e18f..15991cc07 100644 --- a/gui/utils/numberFormatter.py +++ b/gui/utils/numberFormatter.py @@ -1,5 +1,7 @@ import math +from eos.utils.round import roundToPrec, roundDec + def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=False, unitName=None): """ @@ -97,29 +99,3 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal else: result = "{}{} {}{}".format(sign, mantissa, suffix, unitName) return result - - -def roundToPrec(val, prec, nsValue=None): - """ - nsValue: custom value which should be used to determine normalization shift - """ - # We're not rounding integers anyway - # Also make sure that we do not ask to calculate logarithm of zero - if int(val) == val: - return int(val) - roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1) - # But we don't want to round integers - if roundFactor < 0: - roundFactor = 0 - # Do actual rounding - val = round(val, roundFactor) - # Make sure numbers with .0 part designating float don't get through - if int(val) == val: - val = int(val) - return val - - -def roundDec(val, prec): - if int(val) == val: - return int(val) - return round(val, prec)