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:
- Round the decimal number to 2 decimal places.
- Convert the decimal number to an integer.
- Calculate the length of the rounded decimal number and the integer.
- Calculate the difference between the length of the rounded decimal number and the integer.
- If there are 2 decimal places in the rounded decimal number, it should be 3 characters longer than the integer (decimal and the two numbers, e.g. 125.65 vs 126).
- If there is 1 decimal place in the rounded decimal number, it should be 2 characters longer than the integer (decimal and one number, e.g. 125.6 vs 126).
- If there are 0 decimal places in the rounded decimal number, it should be the same length as the integer.
- If the length difference is 2, that indicates that there is only one number after the decimal in the rounded decimal number. Assuming this means that a 0 was dropped, add the 0 back to the end of the string. If the length difference is not 2, don't add anything to the end of the string.
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.