• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Problem with number format

# Problem with number format

Explorer ,
Jun 26, 2024 Jun 26, 2024

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 ?

TOPICS
PDF , PDF forms , Standards and accessibility

Views

146

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
3 Replies 3
Community Expert ,
Jun 26, 2024 Jun 26, 2024

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);``````

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Explorer ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jun 26, 2024 Jun 26, 2024

Copy link to clipboard

Copied

LATEST

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.