adding thousands comma in currency format in custom script

0

I have custom script that formats a value as currency (with 0 decimal places), but I need it to also add in the thousands comma separator. Any help would be appreciated! Here is an example of the current code:

[question(‘value’), id=’mp’,moneyformat=’0’] — returns value of “$15000” instead of “$15,000”

Thanks!

Jim W (Moderator) answered
    1

    It is a custom PHP script.  In pseudo code it would look something like this:

    %%xvalue = sgapiGetValue(20); // get the response value to be formatted
    %%decimals = 0;
    %%dec_point = ”;
    %%thousands_sep = ‘, ‘
    %%xformattedvalue = ‘$’ .  sgapiNumberFormat(%%value,%%decimals,%%dec_point,%%thousands_sep);

    If you prefer, you can skip defining the decimals, decimal point, and thousands separator as variables and just plug them into the NumberFormat function.

    There is no function for adding a currency sign, but it is easy enough to insert it in front of the function.

    The last step of your script depends on what you want to do with the formatted value.

     

    Jim W (Moderator) edited answer
      0

      I suspect it will, I’m just not sure how to incorporate it so that it works.

      andrew answered
        0

        I wonder if this function will help in further formatting the output:

        https://script.surveygizmo.com/help/sgapinumberformat

        Dominic Sharpe answered
          ×

          Login

          Question stats

          • Active
          • Views594 times
          • Answers3 answers
          • Followers1 follower