Copy link to clipboard
Copied
Hi,
It seems a simple matter. Last page of the attached file (7). We have a summary of the amounts in the column above. The three amounts that make up the total (e_total) do not have an amount after the decimal point, but the format of the total field indicates the value: 643 888,00.
How do I change the format of the sum field so that no decimal value appears if the amounts above do not have a decimal value ?
Copy link to clipboard
Copied
You can use something like this as the field's custom calculation script, but I'm getting strange errors from this file. It seems to be corrupt.
var fieldsToAdd = ["e_41", "e_42", "e_43", "e_44"]; // enter the names of the fields to add here
var total = 0;
for (var i=0; i<fieldsToAdd.length; i++) {
var f = this.getField(fieldsToAdd[i]);
if (f!=null) total+=Number(f.valueAsString);
else console.println("ERROR: " + fieldsToAdd[i])
}
if (total==Math.round(total)) event.value = total.toFixed(0);
else event.value = total.toFixed(2);
Copy link to clipboard
Copied
Thank you for your answer !
Unfortunately, this does not work.
If I enter a value such as 777 777,23 in one of the fields to sum, then in the sum field I get 'NaN'.
Is it possible to simply modify the format script below ?
if(event.value){
event.value = util.printf("%,2.2f",event.value).toString().replace(/\./gim," ");}
Please look at 'example.png' file
Copy link to clipboard
Copied
Under the Format option you need to select Number, with the desired pattern, and then enter it using a period as the separator. Or you need to use a more complex script to convert what you entered into a number as JS knows it.