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

Remove 0.00 from calculated field

Community Beginner ,
May 21, 2020 May 21, 2020

Good day,

I created an invoice. Actually very simple. Quantity times price gives amount. I have 4 calculation fields. If I only want to use 1 field there will be 0.00 in the not used calculations. I would like those lines to stay empty. Is there a way to do this? the calculation in the amount field is QTY1*PRICE1......up to QTY4*PRICE4. Thank you!

 

 

 

calculation.JPG

TOPICS
Acrobat SDK and JavaScript
2.6K
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

correct answers 1 Correct answer

Community Expert , May 22, 2020 May 22, 2020

HI,

we can just add an else to your if to set the format, something like:

if ( event.value == 0) {
event.value = "";
}else {
var temp = +event.value; // this line is to make sure the variable is a number.
event.value = temp.toFixed(2);
}

Regards

 

Malcolm

Translate
Community Expert ,
May 21, 2020 May 21, 2020

Hi,

 

I am not sure how you calculation works, but could you not place an if and check if the value is 0, and therefore return "". Just a thought.

 

If you post you calculation code, it would be easier for us to suggest a solution.

Regards

Malcolm

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 Beginner ,
May 21, 2020 May 21, 2020

Hi Malcolm, please see screenshot. It is a very easy calculation. If you have an idea, please let me know! thanks

 

calc2.JPG

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 ,
May 21, 2020 May 21, 2020

Hi,

 

If you add a custom validation script you can change it - something like

 

BarlaeDC_0-1590069307432.png

Regards

 

Malcolm

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 Beginner ,
May 21, 2020 May 21, 2020

Thank you. I did see that script but didn't know where to put it. The code is working now but the output of the calculated field lost its decimals. The amount of 10.00 comes out of 10

Any solution for that? Thank you very much for your help!

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 ,
May 21, 2020 May 21, 2020

That validation script will not affect the output formatting. 

So the problem must be with the formatting option. What do you have selected?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
May 22, 2020 May 22, 2020

Hi Thom, I placed the script in format category "custom" but it replaces the original "numbers" category so the output is a figure without decimals. I can't think it should be that difficult. I also found out that it is not possible to divide so I had to figure out a way to calculate VAT. That works well. Now just to remove the 0.00 in not used calculation lines. Thank you!!

 

calc3.JPG

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 ,
May 22, 2020 May 22, 2020

HI,

we can just add an else to your if to set the format, something like:

if ( event.value == 0) {
event.value = "";
}else {
var temp = +event.value; // this line is to make sure the variable is a number.
event.value = temp.toFixed(2);
}

Regards

 

Malcolm

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 Beginner ,
May 22, 2020 May 22, 2020

Hi Malcolm, Thank you!! This works great!! I am sure this can help a lot of people making invoice forms in Adobe. Much appreciated!! Thanks again!! Best regards, Rob

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 Beginner ,
May 22, 2020 May 22, 2020

Hi Malcolm, just one last thing..... it would be great if the output 1234.55 could be like this: 1,234.55

Thanx! Best regards, Rob

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 ,
May 22, 2020 May 22, 2020

Hi,

 

a little regex can solve that

if ( event.value == 0) {
event.value = "";
}else {
var temp = +event.value;
event.value = temp.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

 

Regards

Malcolm

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 Beginner ,
May 22, 2020 May 22, 2020

Thanks again. It is absolutely perfect now!!

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 ,
May 23, 2020 May 23, 2020

How about just using the regular formatted print function?

 

event.value = util.printf("%,0.2f",event.value);

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
May 24, 2020 May 24, 2020

Thank you Thom, your help is much appreciated. It is working perfect now!

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 Beginner ,
Jul 10, 2020 Jul 10, 2020

This worked perfectly. Thank you. What would you change if you still need it to be dollar amount $

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 ,
Jul 10, 2020 Jul 10, 2020

event.value = util.printf("$%,0.2f",event.value);

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Jul 10, 2020 Jul 10, 2020
LATEST

Perfect.  Thank you.

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
New Here ,
May 25, 2020 May 25, 2020

I tried this solution as a solution to my PPP appllication post, and it got rid of the 2nd date field, it is now blank, but now the 56th day won't calculate.

 

Here's what i typed in:

 

if ( Covered_Period == 0) {
to = "";
}else {
var v = getField("Covered_Period").valueAsString;
// Convert string to date

var d = util.scand("mm/dd/yy", v);
// Add 56 days

d.setDate(d.getDate() + 56);

event.value = util.printd("mm/dd/yyyy", d);
}

 

Any ideas, thx?

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 ,
May 25, 2020 May 25, 2020

Please post to a new thread

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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