Commit bd731933 authored by Kevin Deldycke's avatar Kevin Deldycke

Don't just truncate value.

Round it really.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6712 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 736ad62a
......@@ -69,7 +69,22 @@
<value> <string encoding="cdata"><![CDATA[
try:\n
return float( (\'%.\' + str(precision) + \'f\') % float(value))\n
# Round the value\n
# Fortunately, the round() python method follow french fiscal rules.\n
# Exemples:\n
# 116.5049 should be rounded to 116.50\n
# 116.505 should be rounded to 116.51\n
# 116.5051 should be rounded to 116.51\n
# Please check in your country if the round() method comply with local accounting and fiscal laws.\n
rounded_value = round(value, precision)\n
\n
# Truncate the rounded value\n
trunc_value = (\'%.\' + str(precision) + \'f\') % rounded_value\n
\n
if as_string:\n
return trunc_value\n
return float(trunc_value)\n
\n
except:\n
context.log("bad convertion >>>", repr(context) + " | " + repr(value) + " | " + repr(precision))\n
return 0.0\n
......@@ -95,7 +110,7 @@ except:\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>value, precision</string> </value>
<value> <string>value, precision, as_string=False</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
......@@ -115,7 +130,7 @@ except:\n
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>2</int> </value>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
......@@ -123,8 +138,12 @@ except:\n
<tuple>
<string>value</string>
<string>precision</string>
<string>float</string>
<string>as_string</string>
<string>round</string>
<string>rounded_value</string>
<string>str</string>
<string>trunc_value</string>
<string>float</string>
<string>_getattr_</string>
<string>context</string>
<string>repr</string>
......@@ -139,7 +158,9 @@ except:\n
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
<tuple>
<int>0</int>
</tuple>
</value>
</item>
<item>
......
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