Getting values to display number up to two decimal points


Author
Message
aghartley
aghartley
Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)
Group: Awaiting Activation
Posts: 16, Visits: 127
Hello,

I am programming a task in which participants can earn money by guessing correctly. The cumulative money they have won is displayed in the corner of the screen so they can keep track of how much money they've made. I'd like the text to display they money they've made, with two zeros after the decimal point so it looks like a monetary value (e.g., $3.50), rather than what it shows now, which is just one place after the decimal ($3.5). How would I do this? Here's are some sample pieces of code that are relevant. Thanks in advance for your help!

**where I define value parameters:

<values moneyparams>
/ balance_total = 2.00
/ prevtotal = 0
/ currency = "$"
/ gainincentive = .50
/ loseincentive = .50
/ correctguess = 0
/ correctguessIn = 0
</values>

**where I define the text that displays the participant's balance.

<text balance_total>
/ items = ("<%values.currency%> <%values.balance_total%> ")
/ fontstyle = ("Verdana", 4.0%, true, false, false, false, 5, 0)
/ halign = left
/ hjustify = center
/ vjustify = center
/ size = (25%, 10%)
/ position = (80%, 16%)
/ txcolor = (green)
/ txbgcolor = (black)
/ erase = false
</text>

Dave
Dave
Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)Supreme Being (775K reputation)
Group: Administrators
Posts: 9.9K, Visits: 49K
You can use the the format() function to do that:

<values moneyparams>
/ balance_total = 2.00
/ prevtotal = 0
/ currency = "$"
/ gainincentive = .50
/ loseincentive = .50
/ correctguess = 0
/ correctguessIn = 0
</values>

**where I define the text that displays the participant's balance.

<text balance_total>
/ items = ("<%values.currency%> <%format(~"%.2f~", values.balance_total)%> ")
/ fontstyle = ("Verdana", 4.0%, true, false, false, false, 5, 0)
/ halign = left
/ hjustify = center
/ vjustify = center
/ size = (25%, 10%)
/ position = (80%, 16%)
/ txcolor = (green)
/ txbgcolor = (black)
/ erase = false
</text>

<trial mytrial>
/ ontrialbegin = [values.prevtotal=values.balance_total]
/ ontrialend = [values.balance_total=values.prevtotal+values.gainincentive]
/ stimulusframes = [1=balance_total]
/ validresponse = (57)
</trial>

<block myblock>
/ trials = [1-5=mytrial]
</block>




GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search