Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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/
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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/
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
You're welcome.
Copy link to clipboard
Copied
You can do it like this:
Math.floor(X/10)
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Use it in the field's calculation script, then.
Copy link to clipboard
Copied
I tried it in Simplified and in Custom. The variable is still calculating as the original value with a single decimal place.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more