货币¶
In many experiments, participants play for currency:
either real money, or points. oTree supports both;
you can switch from points to real money by setting USE_POINTS = False
in your settings.
You can write c(42)
to represent “42 currency units”.
It works just like a number
(e.g. c(0.1) + c(0.2) == c(0.3)
).
The advantage is that when it’s displayed to users, it will automatically
be formatted as $0.30
or 0,30 €
, etc., depending on your
REAL_WORLD_CURRENCY_CODE
and LANGUAGE_CODE
settings.
使用 CurrencyField
在数据库中存储货币。例如:
class Player(BasePlayer):
random_bonus = models.CurrencyField()
要创建货币值的列表,使用 currency_range
:
currency_range(c(0), c(0.10), c(0.02))
# this gives:
# [$0.00, $0.02, $0.04, $0.06, $0.08, $0.10]
在模板中,你应当使用 |c
过滤器而不是 c()
函数。举例来说, {{ 20|c }}
会显示为 20 points
.
收益¶
每位玩家都有一个 payoff
字段。如果你的玩家获得了钱,你应当将其存在此字段中。 participant.payoff
自动存储了所有子会话的收益之和。你可以直接修改 participant.payoff
,例如将最终收益四舍五入变为整数。
在实验结束时,参与人的总收益可以通过 participant.payoff_plus_participation_fee()
获取;这是通过将 participant.payoff
转换为真实世界的货币(如果 USE_POINTS
为 True
),再加上 session.config['participation_fee']
计算得来的。
点数(即“实验货币”)¶
你可以设置 USE_POINTS = True
,那么货币值就会使用点数而不是美元/欧元/等等。举例来说, c(10)
会被显示为 10 points
(或者 10 puntos
, 诸如此类)
你可以通过在你的session config中增加一个 real_world_currency_per_point
条目来决定到实际货币的转化率。
将点数转换为现实世界货币¶
你可以通过 .to_real_world_currency()
方法来将点数转换为钱。例如:
c(10).to_real_world_currency(player.session)
( session
是必须的,因为不同的会话会有不同的转换率)。
小数点数位¶
钱数使用小数点后两位展示。
从另一方面说,点数都是整数。这意味着数值会被四舍五入为整数,如 10
除以 3
是 3
。所以,我们推荐使用足够大数量级的点数,这样就不用担心舍入的错误。举例来说,将某个游戏的捐赠设为1000点,而不是100.