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

Truncating (x/10)

Community Beginner ,
Dec 16, 2020 Dec 16, 2020

I have a variable, X.

I need to divide that variable by 10.

X/10 is not the problem. I can do that with the "Calculate" tab.

The problem is that I need a whole number based on the truncated value of (X/10).

I have tried TRUNC(X/10). I still get a decimal.

I have teied FLOOR(X/10). Same response.

How do I get a truncated value, and what do I type where tomake it work?

Thanks!

TOPICS
How to , PDF forms
1.4K
Translate
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Dec 18, 2020 Dec 18, 2020

Well, in that case, since you 're familiarized with INT(X) in BASIC, then you can employ the parseInt() method using 10 as the base number to convert a string to a whole number using Acrobat JavaScript.

 

I am using a custom format script in the event target field like this:

 

 

var f = event.value/10;
event.value = parseInt(f, 10);

 

 

See more parse methods here: https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/

 

View solution in original post

Translate
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 ,
Dec 26, 2020 Dec 26, 2020

Yay! Thank you so much!

Just so I understand whata's happening:

(1) We chnage the string variable "Input" into a numeric value with Get.this

(2) We then used the new numeric value to obtain the truncated vallue.

 

Yeah.. In BASIC, I would have made the inout variable a numberic value, but in the script in Acrobat (because it is placed in a calculation field based on a non-numeric input field), I had to convert AND do thew math.

 

Yeah! I get that.

 

Thank yu again!

View solution in original post

Translate
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 ,
Dec 16, 2020 Dec 16, 2020

What works on my end is a custom format script:

 

 

event.value = util.printf("%.0f", event.value/10);

 

 

I am using the util.printf() method.  This is not the same as truncating it rounds up the event value in the target field and appear as a whole number .

 

Is this what you're inquiring about?

Translate
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 ,
Dec 18, 2020 Dec 18, 2020

I don't think so. I need to eliminate the Phantom Fractions completely, so that a value of 38/10 = 3 with no decimal hiding anywhere, or 33/10 = 3 with no decimal. I'm not wanting to round. Iused to do this in BASIC all the time with the INT(X) command.

Translate
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 ,
Dec 18, 2020 Dec 18, 2020

Well, in that case, since you 're familiarized with INT(X) in BASIC, then you can employ the parseInt() method using 10 as the base number to convert a string to a whole number using Acrobat JavaScript.

 

I am using a custom format script in the event target field like this:

 

 

var f = event.value/10;
event.value = parseInt(f, 10);

 

 

See more parse methods here: https://gomakethings.com/converting-strings-to-numbers-with-vanilla-javascript/

 

Translate
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 ,
Dec 19, 2020 Dec 19, 2020

This looks similar to the BASIC command, but I am getting lost in the syntax... If my variable is called "Input," and I want to truncate (Input/10), where do I put my variable name in your example?

Translate
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 ,
Dec 19, 2020 Dec 19, 2020

I didn't know where you were running the code from, so I assumed it was in the target event field.. that is why I am using event.value in the absence of a declared variable.

 

But If the total value is the result of a calculation that is not performed in the target event field and "Input" is another text field object,  then declare your variable for the field named "Input" like:

 

var Input = this.getField("Input").value/10;
event.value = parseInt(Input, 10);

 

 

Translate
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 ,
Dec 26, 2020 Dec 26, 2020

Yay! Thank you so much!

Just so I understand whata's happening:

(1) We chnage the string variable "Input" into a numeric value with Get.this

(2) We then used the new numeric value to obtain the truncated vallue.

 

Yeah.. In BASIC, I would have made the inout variable a numberic value, but in the script in Acrobat (because it is placed in a calculation field based on a non-numeric input field), I had to convert AND do thew math.

 

Yeah! I get that.

 

Thank yu again!

Translate
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 ,
Dec 26, 2020 Dec 26, 2020
LATEST

You're welcome.

Translate
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 ,
Dec 17, 2020 Dec 17, 2020

You can do it like this:

Math.floor(X/10)

Translate
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 ,
Dec 18, 2020 Dec 18, 2020

Math.floor(x/10) DOES work visibly,  but the value is still showing a single decimal. I need my calculations based on that number (and others like it) to be unaffected by Phantom Fractions. Is there a way to keep the truncated whole number as the value?

Translate
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 ,
Dec 18, 2020 Dec 18, 2020

Use it in the field's calculation script, then.

Translate
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 ,
Dec 18, 2020 Dec 18, 2020

I tried it in Simplified and in Custom. The variable is still calculating as the original value with a single decimal place.

Translate
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