Decimal Places showing up

263 views
Skip to first unread message

Nitin Ramachandran

unread,
Apr 8, 2021, 10:20:29 PM4/8/21
to oTree help & discussion
Hi,

I am trying to display to the users that your total payout is:

(inside vars_for_template)
actual_payoff = (some calculations equalling ~3000)/3600

When I display this to my html file, I keep on getting that this equals 1. 
I really want it to display 0.80 or 0.70 or whatever it happened to be (a number a less than 1 usually) but it seems to round each time

I have USE_POINTS = True

the some calculations equalling ~3000 is arithmetic done with many currencyFields
I have tried using c(3600) but that doesn't seem to work either

Nitin Ramachandran

unread,
Apr 8, 2021, 10:23:20 PM4/8/21
to oTree help & discussion
I also set the variable actual_payoff to be a currencyField as well

Chris @ oTree

unread,
Apr 8, 2021, 10:41:10 PM4/8/21
to oTree help & discussion
Points are integers. See the note at the bottom here: https://otree.readthedocs.io/en/latest/currency.html#decimal-places
Best solution is to choose higher point magnitudes, like play for 30000 points instead of 3000.

Nitin Ramachandran

unread,
Apr 8, 2021, 10:49:00 PM4/8/21
to oTree help & discussion
Would points being 300000/360000 still result in a 1 instead of 0.83?

Chris @ oTree

unread,
Apr 8, 2021, 11:11:49 PM4/8/21
to oTree help & discussion
It's hard to give a recommendation since I don't know the context for this calculation. For example if 3600 is a unit of time (representing the seconds in 1 hour), then there would be no reason to add 0's at the end. Anyway, oTree's currency units are all fixed precision, regardless of the number of decimal places you can have rounding error. if you prefer you can convert those values to float instead.

Nitin Ramachandran

unread,
Apr 8, 2021, 11:19:23 PM4/8/21
to oTree help & discussion
Makes sense, thanks for the help!
Reply all
Reply to author
Forward
0 new messages