Highlighted

PROFIT AND COST

New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

Hello.I have made this code 

1.PROFIT

// Get field values as numbers

 

    var v1 = +getField("Text Field45").value;

 

    var v2 = +getField("Text Field35").value;

    var v3 = +getField("Text Field49").value;

   var v4 = +getField("Text Field48").value;

 

 

    // calculate this field value

 

    event.value = v1- v2+v3-v4;

if(event.value<0)event.value="";

2.COST

// Get field values as numbers

 

    var v1 = +getField("Text Field45").value;

 

    var v2 = +getField("Text Field35").value;

    var v3 = +getField("Text Field49").value;

   var v4 = +getField("Text Field48").value;

 

 

    // calculate this field value

 

    event.value = v1- v2+v3-v4;

if(event.value>0)event.value="";

It works but i would like in the second part (COST) to disappear the negative symbol (-) at the result.For examble if the result is -110 i would like to be 110.

Thanks

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use this:

if (event.value < 0) event.value = -event.value;
else event.value="";

and change the text color of the field

TOPICS
PDF forms

Views

43

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

PROFIT AND COST

New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

Hello.I have made this code 

1.PROFIT

// Get field values as numbers

 

    var v1 = +getField("Text Field45").value;

 

    var v2 = +getField("Text Field35").value;

    var v3 = +getField("Text Field49").value;

   var v4 = +getField("Text Field48").value;

 

 

    // calculate this field value

 

    event.value = v1- v2+v3-v4;

if(event.value<0)event.value="";

2.COST

// Get field values as numbers

 

    var v1 = +getField("Text Field45").value;

 

    var v2 = +getField("Text Field35").value;

    var v3 = +getField("Text Field49").value;

   var v4 = +getField("Text Field48").value;

 

 

    // calculate this field value

 

    event.value = v1- v2+v3-v4;

if(event.value>0)event.value="";

It works but i would like in the second part (COST) to disappear the negative symbol (-) at the result.For examble if the result is -110 i would like to be 110.

Thanks

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Use this:

if (event.value < 0) event.value = -event.value;
else event.value="";

and change the text color of the field

TOPICS
PDF forms

Views

44

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
Sep 10, 2020 0
Engaged ,
Sep 10, 2020

Copy link to clipboard

Copied

EDIT:

You can use this:

var v1 = +getField("Text Field45").value;
var v2 = +getField("Text Field35").value;
var v3 = +getField("Text Field49").value;
var v4 = +getField("Text Field48").value;
var res = v1-v2+v3-v4;
event.value = Math.abs(res.toString());

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...
Sep 10, 2020 0
New Here ,
Sep 11, 2020

Copy link to clipboard

Copied

It doesn’t work. The last line is necessary because if the result is >0 I want it to disappear. The result will appear to the profit. It works perfectly but I would like to appear as positive.

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...
Sep 11, 2020 0
Contributor ,
Sep 11, 2020

Copy link to clipboard

Copied

You are contradicting yourself, " I would like to appear as positive" and yet you don't want to show it if positive?

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...
Sep 11, 2020 0
Engaged ,
Sep 11, 2020

Copy link to clipboard

Copied

You can do it like this: Hide your field where you use calculation and use your code in it:


var v1 = +getField("Text Field45").value;
var v2 = +getField("Text Field35").value;
var v3 = +getField("Text Field49").value;
var v4 = +getField("Text Field48").value;
event.value = v1-v2+v3-v4;
if(event.value>0)event.value="";

 

In the same place create another field and keep it visible and use this code in custom calculation script:


var f1 = this.getField("Text5").value;
event.value = f1 <0 ? Math.abs(f1) : "";


Change name "Text5" to your hidden field name.
Your hidden field name will still be used for calculations and new field will just be showing result as positive or "" if hidden field is positive.

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...
Sep 11, 2020 0
Adobe Community Professional ,
Sep 11, 2020

Copy link to clipboard

Copied

Use this:

if (event.value < 0) event.value = -event.value;
else event.value="";

and change the text color of the field

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...
Sep 11, 2020 1