Rounding Random Numbers | XM Community
Skip to main content
Question

Rounding Random Numbers

  • January 18, 2020
  • 4 replies
  • 129 views

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?

4 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • January 18, 2020
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 ) } ```

  • Author
  • 2 replies
  • January 18, 2020
@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?

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • January 20, 2020
> @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.

  • Author
  • 2 replies
  • January 20, 2020
@TomG thanks for letting me know.