Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with number format

Explorer ,
Jun 26, 2024 Jun 26, 2024

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
651
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2024 Jun 26, 2024

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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 26, 2024 Jun 26, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2024 Jun 26, 2024
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.

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