diff --git a/gui/builtinItemStatsViews/itemAttributes.py b/gui/builtinItemStatsViews/itemAttributes.py index 828c15ff7..45eb6ec04 100644 --- a/gui/builtinItemStatsViews/itemAttributes.py +++ b/gui/builtinItemStatsViews/itemAttributes.py @@ -7,7 +7,7 @@ import wx from .helpers import AutoListCtrl from gui.bitmap_loader import BitmapLoader -from gui.utils.numberFormatter import formatAmount +from gui.utils.numberFormatter import formatAmount, roundDec class ItemParams(wx.Panel): @@ -236,11 +236,13 @@ class ItemParams(wx.Panel): self.Layout() @staticmethod - def FormatValue(value, unit): + def FormatValue(value, unit, rounding='prec', digits=3): """Formats a value / unit combination into a string @todo: move this to a more central location, since this is also used in the item mutator panel""" - if isinstance(value, (int, float)): - fvalue = formatAmount(value, 3, 0, 0) + if isinstance(value, (int, float)) and rounding == 'prec': + fvalue = formatAmount(value, digits, 0, 0) + elif isinstance(value, (int, float)) and rounding == 'dec': + fvalue = roundDec(value, digits) else: fvalue = value return "%s %s" % (fvalue, unit) diff --git a/gui/builtinItemStatsViews/itemMutator.py b/gui/builtinItemStatsViews/itemMutator.py index e196621a3..f2a635c79 100644 --- a/gui/builtinItemStatsViews/itemMutator.py +++ b/gui/builtinItemStatsViews/itemMutator.py @@ -61,15 +61,17 @@ class ItemMutator(wx.Panel): headingSizer.Add(displayName, 3, wx.ALL | wx.EXPAND, 0) - range_low = wx.StaticText(self, wx.ID_ANY, ItemParams.FormatValue(*m.attribute.unit.PreformatValue(round(worse_range[0], 3)))) - range_low.SetForegroundColour(self.goodColor if worse_range[2] else self.badColor) + worst_val = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(worse_range[0]), rounding='dec') + worst_text = wx.StaticText(self, wx.ID_ANY, worst_val) + worst_text.SetForegroundColour(self.goodColor if worse_range[2] else self.badColor) - range_high = wx.StaticText(self, wx.ID_ANY, ItemParams.FormatValue(*m.attribute.unit.PreformatValue(round(better_range[0], 3)))) - range_high.SetForegroundColour(self.goodColor if better_range[2] else self.badColor) + best_val = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(better_range[0]), rounding='dec') + best_text = wx.StaticText(self, wx.ID_ANY, best_val) + best_text.SetForegroundColour(self.goodColor if better_range[2] else self.badColor) - headingSizer.Add(range_low, 0, wx.ALL | wx.EXPAND, 0) + headingSizer.Add(worst_text, 0, wx.ALL | wx.EXPAND, 0) headingSizer.Add(wx.StaticText(self, wx.ID_ANY, " ─ "), 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 5) - headingSizer.Add(range_high, 0, wx.RIGHT | wx.EXPAND, 10) + headingSizer.Add(best_text, 0, wx.RIGHT | wx.EXPAND, 10) mainSizer.Add(headingSizer, 0, wx.ALL | wx.EXPAND, 5) diff --git a/gui/utils/numberFormatter.py b/gui/utils/numberFormatter.py index c79c9e50b..1c4bd29eb 100644 --- a/gui/utils/numberFormatter.py +++ b/gui/utils/numberFormatter.py @@ -110,3 +110,9 @@ def roundToPrec(val, prec): if int(val) == val: val = int(val) return val + + +def roundDec(val, prec): + if int(val) == val: + return int(val) + return round(val, prec)