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

Simple calculation

Explorer ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

Hi I've got very simple question 🙂 please help.

How to make a simple calulation in attached file: B.5 = B.2 + B.3 - B.4.

Somebody could help ? 🙂

 

regards

Wieslaw

TOPICS
PDF forms

Views

1.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 3 Correct answers

Community Expert , Oct 06, 2020 Oct 06, 2020

Try this code as custom calculation script of field '104'

var c1 = parseInt(this.getField("Text6.0").value);
var c2 = parseInt(this.getField("Text6.1").value);
var c3 = parseInt(this.getField("Text6.2").value);
event.value = c1+c2-c3;

You will get rounded result, not sure if thats what you looking for but give it a try.

Votes

Translate

Translate
Community Expert , Oct 06, 2020 Oct 06, 2020

Use this code:

 

var v1 = Number(this.getField("Text6.0").valueAsString.replace(",", "."));
var v2 = Number(this.getField("Text6.1").valueAsString.replace(",", "."));

// Set this field value
event.value = ((v1) !== 0) ? (v1 + v2) : "";

Votes

Translate

Translate
Community Expert , Oct 06, 2020 Oct 06, 2020

Yes. The proper way of doing it is to set the field's Format to Number with that pattern.

Votes

Translate

Translate
Community Expert ,
Oct 05, 2020 Oct 05, 2020

Copy link to clipboard

Copied

In the calculate tab you can use Use the built-in feature "Value is the  sum(+) of the following fields:", or you can use Simplified Field Notation:

 

 

 

(B\.2+B\.3)-B\.4

 

 

Or a custom calculation script of the B.5 field:

 

event.value = (thisgetField("B.2").value + thisgetField("B.3").value) - (thisgetField("B.4").value;

 

 

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
Explorer ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Unfortunately it doesnt't work. Problem should be names of the textfields: "Text6.0", "Text6.1", Text6.2 or my own format script, I don't know. Could you look at attached file ?

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

What exactly are you trying to calculate?

You just want to sum up your fields like this?

Izrezak.PNG

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
Explorer ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

In field '104.' I need simple calculation: field '14'. + field '23' - field '32'.

so: 100,1 + 2,2 - 53

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Try this code as custom calculation script of field '104'

var c1 = parseInt(this.getField("Text6.0").value);
var c2 = parseInt(this.getField("Text6.1").value);
var c3 = parseInt(this.getField("Text6.2").value);
event.value = c1+c2-c3;

You will get rounded result, not sure if thats what you looking for but give it a try.

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
Explorer ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Thank you very much :), it works but small problem is fact that result shouldn't be rounded 🙂

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

IF you're using  the example JavaScript that I posted earlier for you, I made an error.

 

I write "thisgetField". Somehow I missed the period when I was typing. It should read :

 

this.getField

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

The issue is the way you entered the numbers into the fields. Since you used a non-standard notation system (commas as the decimal separators), and not through a regular Number format option, you can't use those values directly in a calculation. You have to first convert them to the format JS recognizes, which is "1234.56", ie. no thousands separators and a period as the decimal separator.
Also, the field names you're referring to in the code under "Text6.10" don't exist.

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Use this code:

 

var v1 = Number(this.getField("Text6.0").valueAsString.replace(",", "."));
var v2 = Number(this.getField("Text6.1").valueAsString.replace(",", "."));

// Set this field value
event.value = ((v1) !== 0) ? (v1 + v2) : "";

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
Explorer ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Super ! one more question, is it possible to replace full stop with a comma in result ? I would like to get "49,3" not "49.3".

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 ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

Yes. The proper way of doing it is to set the field's Format to Number with that pattern.

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
Explorer ,
Oct 06, 2020 Oct 06, 2020

Copy link to clipboard

Copied

LATEST

OK, thanks:)

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