# Rounding currency

**URL:** <https://discuss.tryton.org/t/rounding-currency/5368>\
**Category:** Ideas\
**Tags:** accounting\
**Created:** [June 20, 2022, 12:05pm UTC](https://discuss.tryton.org/t/rounding-currency/5368 "2022-06-20T12:05:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![acaubet](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/acaubet/32/1493_2.png) [@acaubet](https://discuss.tryton.org/u/acaubet)\
**Post date:** [June 20, 2022, 12:05pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/1 "2022-06-20T12:05:35Z")

</div>

I’m wondering why by default we use `ROUND_HALF_EVEN`?  
I know it can be customized by country, but I’m not sure about this default half even when most of the references I can found it’s mentioning to round up:

> If the application of the conversion rate gives a result which is exactly half-way, the sum is rounded up.

> **[Legal certainty: conversion rates and rounding rules | EUR-Lex](https://eur-lex.europa.eu/summary/EN/legissum:l25025)**

Spain for example it’s not determined by law, but the [Tax Base FAQ](https://sede.agenciatributaria.gob.es/Sede/declaraciones-informativas-otros-impuestos-tasas/impuesto-sobre-transacciones-financieras/preguntas-frecuentes-impuesto-transacciones-financieras/base-imponible.html?faqId=bacdea1ac5c0f710VgnVCM100000dc381e0aRCRD) solves the question.

Also I have found some inconsistency in the rounding, which for now I can not understand:

```auto
Currency = pool.get('currency.currency')
eur, = Currency.search([('code', '=', 'EUR')])
from decimal import Decimal
>>> eur.round(Decimal('3.5650'))
Decimal('3.56')
>>> eur.round(Decimal('60.2550'))
Decimal('60.26')

```

---

<div class="post-metadata">

**Author:** ![acaubet](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/acaubet/32/1493_2.png) [@acaubet](https://discuss.tryton.org/u/acaubet)\
**Post date:** [June 20, 2022, 12:06pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/2 "2022-06-20T12:06:54Z")

</div>

FTR the [issue1147](https://bugs.tryton.org/issue1147) is where the rounding was introduced.

---

<div class="post-metadata">

**Author:** ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)\
**Post date:** [June 20, 2022, 12:23pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/3 "2022-06-20T12:23:08Z")

</div>

> [@acaubet](#):
>
> Also I have found some inconsistency in the rounding, which for now I can not understand:
> 
> ```auto
> Currency = pool.get('currency.currency')
> eur, = Currency.search([('code', '=', 'EUR')])
> from decimal import Decimal
> >>> eur.round(Decimal('3.5650'))
> Decimal('3.56')
> >>> eur.round(Decimal('60.2550'))
> Decimal('60.26')
> 
> ```

It’s the way rounding with ROUND\_HALF\_EVEN works: when the last significant number is a five you round towards the even number (so sometimes up, sometimes down).

This choice has been made because it’s the most “fair” way to round numbers because 50% of the time you go up and 50% of the time you go down.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2022, 12:36pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/4 "2022-06-20T12:36:19Z")

</div>

> [@acaubet](#):
>
> [Legal certainty: conversion rates and rounding rules | EUR-Lex](https://eur-lex.europa.eu/summary/EN/legissum:l25025)

This was only for the switch to euro period/

> [@acaubet](#):
>
> Spain for example it’s not determined by law, but the [Tax Base FAQ](https://sede.agenciatributaria.gob.es/Sede/declaraciones-informativas-otros-impuestos-tasas/impuesto-sobre-transacciones-financieras/preguntas-frecuentes-impuesto-transacciones-financieras/base-imponible.html?faqId=bacdea1ac5c0f710VgnVCM100000dc381e0aRCRD) solves the question.

Indeed it does not solve because their definition is incomplete.

This just shows that most country laws can not write clear specifications. But as @nicoe said we choose the fairest way of rounding. But as often the best option is unknown from common people.

---

<div class="post-metadata">

**Author:** ![acaubet](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/acaubet/32/1493_2.png) [@acaubet](https://discuss.tryton.org/u/acaubet)\
**Post date:** [June 20, 2022, 1:39pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/5 "2022-06-20T13:39:58Z")

</div>

> [@ced](#):
>
> Indeed it does not solve because their definition is incomplete.

Which is incomplete for you?

The following is clear for me:

> En caso de que el importe previo al redondeo esté expresado con tres decimales y el tercer decimal sea exactamente la mitad de un céntimo, el redondeo se efectuará por exceso al céntimo superior más próximo.

Which translates to:

> In case of the amount previous to rounding have 3 decimal and third decimal is exactly half on 1 cent, the rounding will be done to the upper cent.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2022, 1:44pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/6 "2022-06-20T13:44:28Z")

</div>

Indeed but if is a FAQ not a law. There should be no problem as long as the same tax rounding rule is always used.

---

<div class="post-metadata">

**Author:** ![timitos](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/timitos/32/323_2.png) [@timitos](https://discuss.tryton.org/u/timitos)\
**Post date:** [June 20, 2022, 1:57pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/7 "2022-06-20T13:57:21Z")

</div>

One point that may need a change of this behavior is the need to be compliant with a 3rdparty software if the data is exported. Most of the ones i know do not use ROUND\_HALF\_EVEN but ROUND\_HALF\_UP as the FAQ is recommending it.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2022, 2:00pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/8 "2022-06-20T14:00:49Z")

</div>

> [@timitos](#):
>
> One point that may need a change of this behavior is the need to be compliant with a 3rdparty software if the data is exported.

If you need to export not raw data but source data that should be computed the same way in different software, you will have much more problem than just that.

> [@timitos](#):
>
> Most of the ones i know do not use ROUND\_HALF\_EVEN but ROUND\_HALF\_UP as the FAQ is recommending it.

I do not see why we should change our good default because other software are bad.

---

<div class="post-metadata">

**Author:** ![timitos](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/timitos/32/323_2.png) [@timitos](https://discuss.tryton.org/u/timitos)\
**Post date:** [June 20, 2022, 2:09pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/9 "2022-06-20T14:09:25Z")

</div>

> [@ced](#):
>
> I do not see why we should change our good default because other software are bad.

I the eyes of any accountant this default is not a good default. But yes, tryton is a framework and it is written for developers. So in the end the developer is responsible to make the framework suitable for the enduser.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [June 20, 2022, 3:27pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/11 "2022-06-20T15:27:32Z")

</div>

> [@ced](#):
>
> > [@timitos](#):
> >
> > Most of the ones i know do not use ROUND\_HALF\_EVEN but ROUND\_HALF\_UP as the FAQ is recommending it.
> 
> I do not see why we should change our good default because other software are bad.

Because we choseen a “fair” rounding but maybe our users prefer to have a more predictable one like HALF\_UP. I’m not sure about it but something to be checked.

I will like to have @albert opinion here as I see [they set the HALF\_UP rounding as default value for Spanish](https://github.com/NaN-tic/trytond-account_es/commit/0e8b6cc3e0cbd8a50de555c800fc7ca8cd674b15) companies back in 2015.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2022, 3:29pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/12 "2022-06-20T15:29:45Z")

</div>

> [@pokoli](#):
>
> Because we choseen a “fair” rounding but maybe our users prefer to have a more predictable one like HALF\_UP.

ROUND\_HALF\_EVEN is as much predictable as any rounding method.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [June 20, 2022, 3:33pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/13 "2022-06-20T15:33:31Z")

</div>

> [@ced](#):
>
> ROUND\_HALF\_EVEN is as much predictable as any rounding method.

What is easly understood for somebody is not easly understood for the everyone.

It seems it is not predictable for somebody that studied Business Administration and Managment as @acaubet did:

> [@acaubet](#):
>
> Also I have found some inconsistency in the rounding, which for now I can not understand:

So that makes me think that account module users that will have diferent toughts.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [June 20, 2022, 3:35pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/14 "2022-06-20T15:35:09Z")

</div>

I stop discussing here because any way this will never change in standard because it would break all the existing accounting.

---

<div class="post-metadata">

**Author:** ![timitos](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/timitos/32/323_2.png) [@timitos](https://discuss.tryton.org/u/timitos)\
**Post date:** [June 20, 2022, 3:49pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/15 "2022-06-20T15:49:16Z")

</div>

I think we could provide a configuration value and store the value in ir.configuration like we do with the default language. This would make it easy to keep the default value for existing databases and to provide a solution to choose another value for new databases.

---

<div class="post-metadata">

**Author:** ![albert](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/albert/32/21_2.png) [@albert](https://discuss.tryton.org/u/albert)\
**Post date:** [June 20, 2022, 4:23pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/16 "2022-06-20T16:23:46Z")

</div>

> [@pokoli](#):
>
> I will like to have @albert opinion here as I see [they set the HALF\_UP rounding as default value for Spanish](https://github.com/NaN-tic/trytond-account_es/commit/0e8b6cc3e0cbd8a50de555c800fc7ca8cd674b15) companies back in 2015.

I guess everything has been said already. HALF\_UP is easier to understand for users and we’d rather spend our time discussing more important things for the company than trying to convince them that the way HALF\_EVEN is more fair. Let alone spend time repeating it every now and then because they forgot about it.

---

<div class="post-metadata">

**Author:** ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)\
**Post date:** [June 20, 2022, 4:24pm UTC](https://discuss.tryton.org/t/rounding-currency/5368/17 "2022-06-20T16:24:07Z")

</div>

Of course there are ways to do some sort of “migration” to support switching the rounding option. But making it a configuration makes it appears like it can be changed when in reality you should not (or at least not during a fiscal year). And what happens when something spans across multiple fiscal years? There are probably ways around that too but it seems to be too much code for so little gain.

But I understand that this behaviour is not the one that 99% of the people expect. People are taught `ROUND_HALF_UP` in primary / middle school and stick to that up until the end sometimes (I learned about `ROUND_HALF_EVEN` when having to deal with scientific measurements).

For me this issue is mainly managing the expectations of your users (and sometimes you have to use `ROUND_HALF_UP` because you can not convince them or whatever) and in that case, it’s just a matter of overriding the default value of `round()`: nothing too complicated.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [June 21, 2022, 7:22am UTC](https://discuss.tryton.org/t/rounding-currency/5368/18 "2022-06-21T07:22:45Z")

</div>

> [@nicoe](#):
>
> For me this issue is mainly managing the expectations of your users (and sometimes you have to use `ROUND_HALF_UP` because you can not convince them or whatever) and in that case, it’s just a matter of overriding the default value of `round()`: nothing too complicated.

Nothing so complicated for the ones that are used to Tryton development and that want to have a custom module for it. But sincerly if you are a system administrator without programing knowledge having to override a method is someway scary.

---

<div class="post-metadata">

**Author:** ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)\
**Post date:** [June 21, 2022, 10:41am UTC](https://discuss.tryton.org/t/rounding-currency/5368/19 "2022-06-21T10:41:21Z")

</div>

> [@pokoli](#):
>
> But sincerly if you are a system administrator without programing knowledge having to override a method is someway scary.

OK I agree but then maybe stick to the default value.

We have to take into account the past and making code to be backward compatible + adding an option seems like a waste of resource and also useless.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [June 21, 2022, 11:12am UTC](https://discuss.tryton.org/t/rounding-currency/5368/20 "2022-06-21T11:12:22Z")

</div>

> [@nicoe](#):
>
> OK I agree but then maybe stick to the default value.

Not sure if you understand. Are you proposing that everybody sticks to `ROUND_HALF_EVEN`?

> [@nicoe](#):
>
> We have to take into account the past

I understand that we should not allow to modify the rounding once the database has been intialized. But this sounds like the same behaviour as we currently have with main language. Once it is set it can not be changed

> [@nicoe](#):
>
> making code to be backward compatible

I do not think we need to make it backward comptabile.

> [@nicoe](#):
>
> adding an option seems like a waste of resource and also useless

So what other options we have?

---

<div class="post-metadata">

**Author:** ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)\
**Post date:** [June 21, 2022, 11:25am UTC](https://discuss.tryton.org/t/rounding-currency/5368/21 "2022-06-21T11:25:04Z")

</div>

> [@pokoli](#):
>
> Not sure if you understand. Are you proposing that everybody sticks to `ROUND_HALF_EVEN`?

What I mean is that if you’re not comfortable creating a module for that then maybe you should stick to the default value. This rounding might be unusual for you but it’s not false.

> [@pokoli](#):
>
> I do not think we need to make it backward comptabile.

Backward compatible as in : making previous database created without the option behave like they did previously. This is required.

Some code will be written to support this. Yes it’s some simple code but its added value is almost 0.

[Next page](https://discuss.tryton.org/t/rounding-currency/5368.md?page=2)
