Currency covert and rounding issue

645 views
Skip to first unread message

Zhang Sr

unread,
Sep 9, 2021, 9:53:53 PM9/9/21
to oTree help & discussion
Hi,

Sorry for asking so much beginner questions. At the final round, I am showing the participant.payoff, but I also want to show  the real world payoff. Thus I am doing the following:

1631238603731.jpg

It works well, but because the payoff is set to be "currency",  and the dollar_payoff is set " float" type, so the result becomes:

Screenshot 2021-09-10 at 9.32.13 AM.png

I do want to remove the "points", and also keep the decimal numbers. Is there anyway I can fix this?

Thank you all, hope you all have a great day.

Shaorong

Chris Crabbe

unread,
Sep 9, 2021, 11:09:11 PM9/9/21
to Zhang Sr, oTree help & discussion
Hi Shaorong -

The way oTree has built-in to accomplish this is to set USE_POINTS=False like in the docs here:  https://otree.readthedocs.io/en/latest/currency.html#currency

Thanks,
--Chris

--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/f8164030-fce1-4749-b1ce-5ef4faeb7ffcn%40googlegroups.com.

BonnEconLab

unread,
Sep 10, 2021, 3:48:28 AM9/10/21
to oTree help & discussion
Hi,

I understand that Shaorong would like to keep the points/dollar distinction, so globally setting USE_POINTS = False might not be the best solution.

However, you can do the conversion locally via

dollar_payoff = float(participant.payoff / 10)

If you want exactly two decimal places in combination with a decimal point, then you can use

dollar_payoff = format(float(participant.payoff / 10), '.2f'))

Finally, if you would like a decimal comma instead of a decimal point, you can use

dollar_payoff = format(float(participant.payoff / 10), '.2f')).replace(".", ",")

Beyond that, oTree offers built-in methods for converting points to real-world currency units via the parameter real_world_currency_per_point and the method .to_real_world_currency(session), see https://otree.readthedocs.io/en/latest/currency.html.

Best,

Holger

Reply all
Reply to author
Forward
0 new messages