Commit 3ae95532 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Log based calculation of precision

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10097 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d7a59ae2
...@@ -27,8 +27,9 @@ ...@@ -27,8 +27,9 @@
# #
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from math import log
from AccessControl import ClassSecurityInfo
from DateTime import DateTime from DateTime import DateTime
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
...@@ -708,8 +709,11 @@ class Resource(XMLMatrix, CoreResource, Variated): ...@@ -708,8 +709,11 @@ class Resource(XMLMatrix, CoreResource, Variated):
def getQuantityPrecision(self): def getQuantityPrecision(self):
"""Return the floating point precision of a quantity. """Return the floating point precision of a quantity.
""" """
quantity = str(self.getBaseUnitQuantity()) try:
i = quantity.find('.') return int(round(- log(self.getBaseUnitQuantity(), 10),0))
if i < 0: except TypeError:
return 0 return 0
return len(quantity[i+1:].rstrip('0')) return 0
\ No newline at end of file
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