Is there a way to format the Survey123 Custom Print Template to round decimal places to two decimal places? My survey form is currently collecting values by using round(${TotalPayment},2), but when I go to use my custom print template that I created it doesn't keep this formatting. It seems to drop a 0. For my attached example my total payment is $65.60, but right now when I generate my custom print template it puts $65.6, dropping that 0 at the end.
It would be nice that for my dollar figures in my custom print template, would keep the two decimal places that I am collecting in my form or have a way to format it in the custom print template. Thank you for your help.
Edit: This is for a new survey, rather than an existing survey. Not sure if there's a workaround for an existing survey.
The round() function automatically drops the 0. I don't think there's a way to change that, but if you convert the number to a string there are some ways you could format it the way you want, then display that string in the report.
I haven't come across an easy way to do this with the functions available, but I came up with a way that has worked for me. My logic:
Fields in my example XLSForm spreadsheet:
type | name | label | calculation | bind::esri:fieldType |
---|---|---|---|---|
decimal | input | Input | ||
calculate | total | Total | ${input}*5 | |
calculate | tot_rounded | Rounded total | round(${total},2) | |
calculate | tot_as_int | Total as integer | int(${total}) | null |
calculate | len_tot_rounded | Length of rounded total | string-length(${tot_rounded}) | null |
calculate | len_tot_as_int | Length of total as integer | string-length(${tot_as_int}) | null |
calculate | len_diff | Length difference | ${len_tot_rounded} - ${len_tot_as_int} | null |
calculate | tot_as_text | Total as text | if(${len_diff}=2, concat('$',${tot_rounded},'0'), concat('$',${tot_rounded})) |
In this example, you could then display ${tot_as_text} in the report rather than the rounded total as calculated by the round() function. The attached image shows the table from this example survey after a few submissions.
Thank you for your help. I'll have to see if this will be feasible to add to my existing survey. And see if this can help for our contract sign up next year. I appreciate it!