[Erp5-report] r34055 kazuhiko - /erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Mar 24 16:04:34 CET 2010
Author: kazuhiko
Date: Wed Mar 24 16:04:32 2010
New Revision: 34055
URL: http://svn.erp5.org?rev=34055&view=rev
Log:
support roundings.
Modified:
erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py
Modified: erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py?rev=34055&r1=34054&r2=34055&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/FloatEquivalenceTester.py [utf8] Wed Mar 24 16:04:32 2010
@@ -56,6 +56,7 @@
, PropertySheet.DublinCore
, PropertySheet.EquivalenceTester
, PropertySheet.SolverSelection
+ , PropertySheet.DecimalOption
)
# Declarative interfaces
@@ -78,6 +79,10 @@
if self.getProperty('use_delivery_ratio') and \
prevision_movement.getDelivery() == decision_movement.getRelativeUrl():
decision_value *= prevision_movement.getDeliveryRatio()
+
+ if self.isDecimalAlignmentEnabled():
+ decision_value = self._round(decision_value)
+ prevision_value = self._round(prevision_value)
delta = decision_value - prevision_value
# XXX we should use appropriate property sheets and getter methods
@@ -145,10 +150,23 @@
dict(property_name=tested_property,
value=relative_tolerance_max))
return None
- # XXX the followings are not treated yet:
- # * decimal_alignment_enabled
- # * decimal_rounding_option
- # * decimal_exponent
+
+ def _round(self, value):
+ from decimal import (Decimal, ROUND_DOWN, ROUND_UP, ROUND_CEILING,
+ ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN,
+ ROUND_HALF_UP)
+ # Python2.4 did not support ROUND_05UP yet.
+ rounding_option_dict = {'ROUND_DOWN':ROUND_DOWN,
+ 'ROUND_UP':ROUND_UP,
+ 'ROUND_CEILING':ROUND_CEILING,
+ 'ROUND_FLOOR':ROUND_FLOOR,
+ 'ROUND_HALF_DOWN':ROUND_HALF_DOWN,
+ 'ROUND_HALF_EVEN':ROUND_HALF_EVEN,
+ 'ROUND_HALF_UP':ROUND_HALF_UP}
+ rounding_option = rounding_option_dict.get(self.getDecimalRoundingOption(),
+ ROUND_DOWN)
+ return Decimal(str(value)).quantize(Decimal(self.getDecimalExponent()),
+ rounding=rounding_option)
def getUpdatablePropertyDict(self, prevision_movement, decision_movement):
"""
More information about the Erp5-report
mailing list