0

I am quiet new to oTree and to programming as such. My problem is with the rounding up of my payoff. So, £11.50 becomes £12.00. I tried my best to figure out a way to stop this but haven't been able to figure out anything yet. I have created a separate app for this.

This is the code I am using:

class Payment(Page):
    @staticmethod
    def vars_for_template(player: Player):
        participant = player.participant
        return dict(
            redemption_code=participant.label or participant.code,
            earning = format(float(participant.payoff / 10), '.2f')
        )
Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

0

I have been able to solve this problem. This is what I have done:

@staticmethod
def vars_for_template(player: Player):
    # generate a random outcome as "pchoice"
    # determine whether they can get payoff == whether a random number from [0,1] can be less than 0.5
    pchoice = np.random.random()
    if pchoice <= 0.5:
        player.get_payoff = 1
    else:
        player.get_payoff = 0
    # determine the payoff
    # since get_payoff = 1 or 0, we can multiply directly to get the final payoff
    if player.decision == True:
        player.payoff += C.payment_assetA*player.get_payoff
    if player.decision == False:
        player.payoff += C.payment_assetB*player.get_payoff
    if player.get_payoff == 0:
        player.payoff += C.payment_otherwise
    return dict(
        earning = format(Decimal(player.payoff) / Decimal(10), '.2f')
    )