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

Fillable PDF with feet and inches in fractions

New Here ,
Nov 17, 2021 Nov 17, 2021

I need to create a fillable PDF that accepts measurements in  inches and fractions of inches.  I need the user to input 3 different values and then have the form calculate what the lowest of those 3 values is.  When I select any type of number format, it won't let me use the fraction format.  Any way to make this work?   

Example:

Field 1: 35"

Field 2: 35 1/4"

Field 3: 35 1/8"

Form should calculate in last field: 35"

TOPICS
How to
1.7K
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 ,
Nov 17, 2021 Nov 17, 2021

You can create a custom format for this or use the format None.

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 ,
Nov 17, 2021 Nov 17, 2021

Is the issue that you can't use these values for a calculation, or that you want to make sure the user enters a valid number?

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
New Here ,
Nov 17, 2021 Nov 17, 2021

The issue is more that I can't use them for a calculation.  If I select the format as none, it won't do the calculatioin.

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 ,
Nov 17, 2021 Nov 17, 2021

There is no build-in calculation for this.

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 ,
Nov 17, 2021 Nov 17, 2021

I've written a generic function that will allow you to convert such texts into a real number:

 

function convertInchesToNumbers(s) {
	if (s=="") return 0;
	s = s.replace(/["']/, "");
	var parts = s.split(" ");
	var total = Number(parts[0]);
	if (parts.length==2) {
		total+=eval(parts[1]);
	}
	if (isNaN(total)) return 0;
	return total;
}

 

You can place it as a doc-level script and then call it like this:

convertInchesToNumbers("35 1/8\"")

This will return 35.125 .

 

Or if you wish to use it to calculate the sum of certain such fields, you can do it like this:

 

event.value = convertInchesToNumbers(this.getField("Field 1").valueAsString) + convertInchesToNumbers(this.getField("Field 2").valueAsString) + convertInchesToNumbers(this.getField("Field 3").valueAsString);

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
New Here ,
May 01, 2024 May 01, 2024

Hello,

 

I'm in a similar situation. I have no experience with Java, so I've been googling and patching code together.

Try67, I've been seeing your name a lot in my search. I am hoping that you can help me.

I am creating a form where a user can enter two dimensions (I will have other forms with up to four values that can be entered) and select where they are taking measurements from. Based on the entered dimension and radio button, I want to make some calculations.

 

1st Calculation:

Calculating the minimum value between two numbers, even if a fractional number is given.

 

I was able to get the minimum value between two numbers, but as soon as the fraction was added, I would get 'NaN'

 

For the two entries, I have put in the following code:

function convertInchesToNumbers(H1) {

            if (H1=="") return "";

            H1 = H1.replace(/["']/, "");

            var parts = x.split(" ");

            var total = Number(parts[0]);

            if (parts.length==2) {

                        total+=eval(parts[1]);

            }

            if (isNaN(total)) return 0;

            return total;

}

 

function convertInchesToNumbers(H2) {

            if (H2=="") return "";

            H2 = H2.replace(/["']/, "");

            var parts = x.split(" ");

            var total = Number(parts[0]);

            if (parts.length==2) {

                        total+=eval(parts[1]);

            }

            if (isNaN(total)) return 0;

            return total;

}

 

//I was going to hide this value. It's easier for me to separate the code, but I would also be okay with having everything in one.

For the calculated minimum value, I've put the following code:

var fields = ["H1", "H2"];
var minValue = Infinity;
for (var i in fields) {
     var f = this.getField(fields[i]);
     if (f==null) {console.println("Error! Can't find: " + fields[i]); continue;}
     var v = f.valueAsString;
     if (v!="") minValue = Math.min(minValue, Number(v));
}
if (minValue==Infinity) event.value = "";
else event.value = minValue;

 

2nd calculation:

When the user selects AFF, a deduction of 0 will be applied. And the field to enter a Thickness will not be visible

When the user selects UFF, the thickness field will be visible, and the entered value will be the deduction.

When the user selects AC, RSO or T, a specific value will be deducted. AC:0, RSO:0.625, T:1.875

 

I haven't reached the section where I need to put everything together. but below is an example

Example:

H1 = 80 1/2

H2 = 90 1/2

UFF: Selected, THICK1 = 5/8

RSO Selected

 

H3 =  80 1/2 - 5/8 - 0.625 = 79 1/4 or 79.25

//This is the final calculation I would need. The method to get there does not matter much.

I want to have two calculated fields, one for decimal and one for fractional values. If this is too much, I would rather use the fractional value. If this is too much, then the decimal will do it.

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 ,
May 01, 2024 May 01, 2024
LATEST

This goes a bit beyond the scope of this forum, in my opinion. I'm happy to work on this for you, for a fee.

If you're interested please contact me privately to discuss it further.

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