Commit a6513ffd authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! RoundingTool: add a utility round() method that supports rounding option.

parent 27c8d4c9
......@@ -60,17 +60,17 @@ class TestRoundingTool(ERP5TypeTestCase):
Test round utility method
"""
rounding_tool = self.portal.portal_roundings
round = rounding_tool.round
self.assertEqual(round(500 * 655.957, 0), 327979.0)
self.assertEqual(round(-0.5), -1)
self.assertEqual(round(0.15, 1), 0.2)
self.assertEqual(round(-0.15, 1), -0.2)
self.assertEqual(round(1.25, 1), 1.3)
self.assertEqual(round(500 * 655.957, 0, 'ROUND_HALF_EVEN'), 327978.0)
self.assertEqual(round(-0.5, 0, 'ROUND_HALF_EVEN'), -0.0)
self.assertEqual(round(0.15, 1, 'ROUND_HALF_EVEN'), 0.2)
self.assertEqual(round(-0.15, 1, 'ROUND_HALF_EVEN'), -0.2)
self.assertEqual(round(1.25, 1, 'ROUND_HALF_EVEN'), 1.2)
round_ = rounding_tool.round
self.assertEqual(round_(500 * 655.957, 0), 327979.0)
self.assertEqual(round_(-0.5), -1)
self.assertEqual(round_(0.15, 1), 0.2)
self.assertEqual(round_(-0.15, 1), -0.2)
self.assertEqual(round_(1.25, 1), 1.3)
self.assertEqual(round_(500 * 655.957, 0, 'ROUND_HALF_EVEN'), 327978.0)
self.assertEqual(round_(-0.5, 0, 'ROUND_HALF_EVEN'), -0.0)
self.assertEqual(round_(0.15, 1, 'ROUND_HALF_EVEN'), 0.2)
self.assertEqual(round_(-0.15, 1, 'ROUND_HALF_EVEN'), -0.2)
self.assertEqual(round_(1.25, 1, 'ROUND_HALF_EVEN'), 1.2)
def testRoundValueMethod(self):
"""
......
......@@ -41,7 +41,7 @@ ROUNDING_OPTION_DICT = {'ROUND_DOWN':ROUND_DOWN,
'ROUND_HALF_EVEN':ROUND_HALF_EVEN,
'ROUND_HALF_UP':ROUND_HALF_UP}
def round(value, ndigits=None, decimal_rounding_option='ROUND_HALF_UP'):
def round(value, ndigits=None, decimal_rounding_option='ROUND_HALF_UP'): # pylint:disable=redefined-builtin
if ndigits is None:
precision = 1
else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment