Highlighted

Remove 0.00 from calculated field

Community Beginner ,
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

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

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

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

763

Likes

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

Remove 0.00 from calculated field

Community Beginner ,
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

Adobe Community Professional
Correct answer by BarlaeDC | Adobe Community Professional

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

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

764

Likes

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
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Community Beginner ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Community Beginner ,
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!

Likes

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
Reply
Loading...
Adobe Community Professional ,
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?

 

Likes

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
Reply
Loading...
Community Beginner ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Community Beginner ,
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

Likes

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
Reply
Loading...
Community Beginner ,
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

Likes

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
Reply
Loading...
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Community Beginner ,
May 22, 2020

Copy link to clipboard

Copied

Thanks again. It is absolutely perfect now!!

Likes

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
Reply
Loading...
Adobe Community Professional ,
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);

 

Likes

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
Reply
Loading...
Community Beginner ,
May 24, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
New Here ,
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 $

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jul 10, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
New Here ,
Jul 10, 2020

Copy link to clipboard

Copied

Perfect.  Thank you.

Likes

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
Reply
Loading...
New Here ,
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?

Likes

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
Reply
Loading...
Adobe Community Professional ,
May 25, 2020

Copy link to clipboard

Copied

Please post to a new thread

 

Likes

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF