oTree-org / oTree

Python framework for multiplayer decision games, behavioral experiments, and surveys
https://groups.google.com/g/otree
Other
464 stars 199 forks source link

POINTS_DECIMAL_PLACES doesn't behave correctly #110

Open somas95 opened 2 years ago

somas95 commented 2 years ago

There are at least two places where POINTS_DECIMAL_PLACES doesn't yield good results.

First, it doesn't respect LANGUAGE_CODE so I'll get a point where a decimal comma is expected in languages like Spanish

Second, round operators won't work properly. The rounding happens but non significative digits are still shown

For example, if the variable a = cu(0.32), and in the template I specify {{ a|to1 }} I'll get 0.30 where 0.3 is expected.

I can write a PR if desired (although the repo hasn't been updated for a while)

oTree-org commented 2 years ago

Hi, thank you for reporting. I was aware of some of these issues, but haven't fixed it yet because it was tricky in the code.

Honestly, I don't recommend using POINTS_DECIMAL_PLACES, and as you can see it is not documented. Using whole numbers avoids a number of complications. My recommendation is to set your point magnitudes high enough that you don't care about rounding error. There is a note about this here: https://otree.readthedocs.io/en/latest/currency.html#decimal-places

somas95 commented 2 years ago

Sadly that's not always possible, but thanks! If you need any help improving that let me know