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

Remove 0.00 from calculated field

Community Beginner ,
May 21, 2020 May 21, 2020

Copy link to clipboard

Copied

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

Views

2.1K

Translate

Translate

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 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

Votes

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

 

calc2.JPG

Votes

Translate

Translate

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

Copy link to clipboard

Copied

Hi,

 

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

 

BarlaeDC_0-1590069307432.png

Regards

 

Malcolm

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

Thanks again. It is absolutely perfect now!!

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

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

Copy link to clipboard

Copied

LATEST

Perfect.  Thank you.

Votes

Translate

Translate

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

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

Copy link to clipboard

Copied

Please post to a new thread

 

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

Votes

Translate

Translate

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 guidelines