Rounding Random Numbers

drmiller1220drmiller1220 St. Louis, MOCommunity Member - Trial User Qubie ✭

Rounding Random Numbers

I am trying to generate a random amount of money to appear in one of my survey questions. I want the random amount to allow for both dollars and cents (i.e., $0.10, $1.25, $10.50, etc.).

I have not been able to figure out how to use the random number generator available in Qualtrics' piped text menu to accomplish this. "$e{ round ( rand://float/0.05:1.50 , 2 ) }" results in "{Invalid Expression}" once evaluated in the survey flow. I have tried some other tweaks, but have not yet gotten it to work the way I want it to.

Could someone help me figure out what I am doing wrong, and how to get the result I want?

Answers

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    You can't use rand in a math expression. Do it in two steps in the survey flow:

    rand = ${rand://float/0.05:1.50}
    rand = $e{ round ( e://Field/rand , 2 ) }
    
  • drmiller1220drmiller1220 St. Louis, MOCommunity Member - Trial User Qubie ✭

    @TomG awesome, that works! Thanks!

    Follow-up question: the rounding function seems to not preserve trailing zeroes when they appear (i.e., $0.60 presents as "$0.6"). Is there anything I can do to preserve the trailing zeroes?

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭

    @drmiller1220 said:
    @TomG awesome, that works! Thanks!

    Follow-up question: the rounding function seems to not preserve trailing zeroes when they appear (i.e., $0.60 presents as "$0.6"). Is there anything I can do to preserve the trailing zeroes?

    Unfortunately, there isn't a way to format the number using a math expression. You would have to use JavaScript to format.

  • drmiller1220drmiller1220 St. Louis, MOCommunity Member - Trial User Qubie ✭

    @TomG thanks for letting me know.

Sign In to Comment