oTree Forum >

Displaying numbers as decimals

#1 by Anonymousguy

Hello,

how can i modify the code in my HTML file so i can display a result (number that has been calculated before) as a decimal. Preferably two decimal points.. my code is as follows:

<h5>Resulting group action: {{ player.payoff }}</h5>

Player payoff has been calculated with a formula in my init file like this: 

p.payoff = average_extraction + additional_payoff_per_group

#2 by ChristianK

Hi!

If you use points as the experimental currency, you are limited to integers. If you are using real currency, player.payoff should be a currency field and display decimals and the right currency symbol automatically. The payoff variable is special in this regard as it deals with currencies.
More info on that here: https://otree.readthedocs.io/en/latest/currency.html

If you are dealing with any other float field, you can format the string on the template: {{ my_float|to2 }}
See: https://otree.readthedocs.io/en/latest/templates.html#miscellaneous

Best
Christian

Write a reply

Set forum username