Rounding decimals

I have used this code in the past when comparing input answers to what I want:

\\operatorname{round}\\left(${expectedValue},2\\right)

and that works, but when it comes to showing a rounded decimal in the content doesnt round. What can I use to round a calculated number and then show it in the displayed content?

Make a variable with that code, and display that should work. The only time I don’t think it works is if there’s a trailing zero.

t=results.script.total
tp=results.script.totalpercent
tpr="\\operatorname{round}\\left(${tp},2\\right)"


content: when numericValue("${t}") = 100 "FANTASTIC ${studentName.content}! You got all ${tp}!!  See the details below:


👈🏿 Tell us how you're doing

"

otherwise "You got `${tpr}` correct out of 100%. Try to go back and fix your work. You got this ${studentName.content}! 

👈🏿 Tell us how you're doing
"

I have it assigned to one, but the image is what happens. plus it still doesnt round

You’re just displaying the latex. Try using numericValue for tpr.

Caused the NaN error

There’s a % character in tp that might be the problem.

1 Like

I’m an idiot… That was it. Thanks for catching that.

1 Like

Debugging is the hardest part!

1 Like