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

PROFIT AND COST

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

TOPICS
PDF forms

Views

447

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 2 Correct answers

Community Expert , Sep 11, 2020 Sep 11, 2020

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) : "";


Ch

...

Votes

Translate

Translate
Community Expert , Sep 11, 2020 Sep 11, 2020

Use this:

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

and change the text color of the field

Votes

Translate

Translate
Community Expert ,
Sep 10, 2020 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());

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

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
Enthusiast ,
Sep 11, 2020 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?

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

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

Copy link to clipboard

Copied

LATEST

Use this:

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

and change the text color of the field

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