psychopy.org | Reference | Downloads | Github

Rounding float return to nearest dollar amount

I am currently running an experiment that asks participants to either answer 'num_1" or “num_2” based on a provided stimulus. If they answer correctly, I provide a positive feedback and then continue on in the experiment. However, if they answer incorrectly, the experiment continues as normal. For each correct answer, they earn an additional $0.05. There are three breaks and a final thank you screen.

Currently, I am just summing up each correct response and multiplying it by 0.05 to get a dollar amount that is presented on the break screens and the final thank you screen. This said, I wish to round this dollar amount to the nearest $5.00 increment as the giftcards we use only come in $5.00 increments.

For example, if a person gets 163/600 they would technically receive $8.15. I would like to round up and display $10.00 instead of $8.15.

My current code is as follows

msg = ''

nCorr = trials_5.data['key_resp_18.corr'].sum()
msg = "You have earned $ %0.2f" %(nCorr * 0.05)

Divide your amount (e.g. 8.15) by 5, make that an integer (e.g. 1), add 1 (e.g. 2) and multiply by 5.

e.g:

8.15 -> 10
47.5 -> 50