summaryrefslogtreecommitdiff
path: root/doc/python3.rst
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-05-17 16:50:52 +0200
committerOlivier Dony <odo@openerp.com>2017-08-19 02:34:20 +0200
commit70599807a163d156f2399c56d698bcf1b876daf3 (patch)
treea894b753fd811e701a99e6f4f3c589f8ccf1fba8 /doc/python3.rst
parentb970bf865a7fa1dfbef0b8a365e39210fb5b75ce (diff)
[FIX] P3: round() compatibility shim
In Python 3 round: * rounds half to even (banker's rounding) rather than up * returns an int if not given a precision (or given a precision of None) * discards the negative sign when rounding to 0 Add a compatibility shim which implements P2 behaviour and at least allows passing float_utils's tests. Implementing float_round on top of Decimal was attempted but did not work: although Decimal.quantize takes a non-integral Decimal (e.g. ``d.quantize(D('0.001'))``) it only supports integral powers of 10 and does not support quantizing to e.g. 0.05: while that will not fail it will just use the exponent for quantization and 0.05 is thus equivalent to 0.01, which is not what we want if e.g. need to round a value to 5 cents. This is hinted at but maybe not clearly spelled out by the official documentation: > Return a value equal to the first operand after rounding > and **having the exponent of** the second operand. Also convert a bunch of hand-rolled currency rounding to just using the round() method on res.currency.
Diffstat (limited to 'doc/python3.rst')
0 files changed, 0 insertions, 0 deletions