diff --git a/common/lib/xmodule/xmodule/progress.py b/common/lib/xmodule/xmodule/progress.py index 4e3a8bc93e..470aa22a0e 100644 --- a/common/lib/xmodule/xmodule/progress.py +++ b/common/lib/xmodule/xmodule/progress.py @@ -116,12 +116,15 @@ class Progress(object): return not self.__eq__(other) def __str__(self): - ''' Return a string representation of this string. + '''Return a string representation of this string. Rounds results to + two decimal places, stripping out any trailing zeroes. subclassing note: implemented in terms of frac(). + ''' (a, b) = self.frac() - return "{0}/{1}".format(a, b) + display = lambda n: '{:.2f}'.format(n).rstrip('0').rstrip('.') + return "{0}/{1}".format(display(a), display(b)) @staticmethod def add_counts(a, b): diff --git a/common/lib/xmodule/xmodule/tests/test_progress.py b/common/lib/xmodule/xmodule/tests/test_progress.py index d821f557ad..e882d719d6 100644 --- a/common/lib/xmodule/xmodule/tests/test_progress.py +++ b/common/lib/xmodule/xmodule/tests/test_progress.py @@ -81,6 +81,9 @@ class ProgressTest(unittest.TestCase): self.assertEqual(str(self.not_started), "0/17") self.assertEqual(str(self.part_done), "2/6") self.assertEqual(str(self.done), "7/7") + self.assertEqual(str(Progress(2.1234, 7)), '2.12/7') + self.assertEqual(str(Progress(2.0034, 7)), '2/7') + self.assertEqual(str(Progress(0.999, 7)), '1/7') def test_ternary_str(self): self.assertEqual(self.not_started.ternary_str(), "none")