Commit c3615c3d authored by Jérome Perrin's avatar Jérome Perrin

When using precision, float fields should round the value before truncating

it.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15251 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f4a953d
...@@ -1052,12 +1052,15 @@ class FloatWidget(TextWidget): ...@@ -1052,12 +1052,15 @@ class FloatWidget(TextWidget):
def format_value(self, field, value): def format_value(self, field, value):
"""Formats the value as requested""" """Formats the value as requested"""
if value not in (None,''): if value not in (None,''):
precision = field.get_value('precision')
input_style = field.get_value('input_style') input_style = field.get_value('input_style')
percent = 0 percent = 0
original_value = value original_value = value
if input_style.find('%')>=0: if input_style.find('%')>=0:
percent=1 percent=1
value = float(value) * 100 value = float(value) * 100
if precision:
value = round(value, precision)
try : try :
value = str(float(value)) value = str(float(value))
except ValueError: except ValueError:
...@@ -1077,7 +1080,6 @@ class FloatWidget(TextWidget): ...@@ -1077,7 +1080,6 @@ class FloatWidget(TextWidget):
i += 3 i += 3
else: else:
value = value_list[0] value = value_list[0]
precision = field.get_value('precision')
if precision != 0: if precision != 0:
value += '.' value += '.'
if precision not in (None,''): if precision not in (None,''):
......
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