Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Show decimals in numeric question

I have a numeric question that is set to allow decimals, but my client may want it to force this format, $00.00.  Is there a way to require/show two decimals?
asked Oct 1, 2021 by Jay Rutherford Platinum (51,195 points)
What does "force" mean here?  You want two decimals appearing all the time?  Or just that responses aren't accepted without exactly two decimal places?
At this point I believe two decimals appearing all the time.
That's possible, but it's not trivial.  You may want to look up JavaScript mask libraries and see if one satisfies your client and meets any licensing requirements, then we can hook up that library with Lighthouse Studio.
Unfortunately time didn't allow me to find what I needed to force two decimals.  Of course now I have another project that is asking for something similar (entering a dollar amount to include cents).

Curious if you have any easy way to not allow more than two decimals?

1 Answer

0 votes
Best answer
Sure, try this custom JavaScript verification:

if (/\.\d{3}/.test(SSI_GetValue('[% QuestionName() %]'))) {
    strErrorMessage = 'error...';
answered Oct 6, 2021 by Zachary Platinum Sawtooth Software, Inc. (208,650 points)
selected Oct 6, 2021 by Jay Rutherford
Does your grid question involve constructed lists?
It does, yes.  The rowlist is constructed.
We could change up the regex test line, but my usual is to read the constructed list items and write the loop like this:

var rows = $('input[name="hid_row_list_[% QuestionName() %]"]').val().split(',');
    if (/\.\d$|\.\d{3}/.test($('#[% QuestionName() %]_r' + row + '_c1').val().trim())) {
        strErrorMessage = 'Your response should be in this format $00.00';
Okay, that is working.  Nice solution.  So what I did would have worked if it wasn't constructed lists then?