PDF Editing Issues

How to Calculate the Lowest of Two PDF Fields and a Fixed Amount

Emma BrownEmma Brown Nov 2, 2026 869 views

Question details

The user needs to dynamically calculate the lowest value between two numeric text fields and a fixed amount ($250,000) and display it in a target PDF field, while evaluating a specific checkbox condition.

How to Calculate the Lowest of Two PDF Fields and a Fixed Amount
Product
PDF Form Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form that requires a conditional mathematical comparison to automatically determine a minimum amount.
Observed behavior
The target field must display the minimum value of field A, field B, and a fixed amount, or return an empty value if specific checkbox conditions are unmet.
Before you start

Ensure that your PDF editor supports JavaScript for form fields and that the source text fields are using numeric formatting rather than storing literal currency symbols.

Solution 1Recommended

Use Custom JavaScript to Find the Minimum Value

Apply a custom calculation script using the Math.min() function to accurately compare form fields and fixed amounts.

Built-in PDF calculation functions only cover basic math like sum, product, or average. To determine a minimum value among variables and a fixed limit, you must use a custom JavaScript function. The Math.min() method evaluates a list of arguments and returns the lowest number.

1
Access Field Properties

Open your PDF form in editing mode, right-click the target field where you want the result to appear, and select 'Properties'.

2
Set Calculation Type

Navigate to the 'Calculate' tab in the Properties dialog and choose the 'Custom calculation script' option.

3
Retrieve Field Values

Click the 'Edit' button and define your variables by converting the source field values into numbers. Enter: var a = Number(this.getField('A3').value); var b = Number(this.getField('A8').value);

4
Calculate the Lowest Value

Add the calculation line to output the lowest of the variables and your fixed amount: event.value = Math.min(a, b, 250000);

5
Save and Test

Click 'OK' to save the script, close the Properties window, and enter numbers into fields A3 and A8 to test the calculation.

Use Custom JavaScript to Find the Minimum Value
Proper Number Formatting: Ensure that your source fields (A3 and A8) are strictly formatted as numbers in their properties. If they store literal text characters like '$' or commas in their raw value, the script may return 'NaN' (Not a Number).
Powerful PDF Form Editor

Easily Create Interactive PDF Forms with WPS Office

WPS Office offers a comprehensive suite of PDF tools, allowing you to seamlessly design fillable forms, configure text fields, and apply advanced JavaScript calculations.

  1. 1. Open PDF Edit Mode: Launch WPS Office, open your PDF document, and navigate to the 'Form' tab.
  2. 2. Insert Form Fields: Use the 'Text Field' and 'Check Box' tools to place interactive input areas exactly where you need them.
  3. 3. Configure Properties: Double-click any field to access its properties, format it as a number, or enter your custom calculation scripts in the 'Calculate' tab.
Fully compatible with standard PDF forms and JavaScript calculations.Intuitive drag-and-drop form building interface.Easily manage field properties, formatting, and validation.Lightweight, fast, and free to download for your daily productivity needs.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF calculation showing 'NaN' instead of a number?

NaN stands for 'Not a Number'. This happens when the script attempts to calculate a text string. To fix this, ensure the source fields do not contain typed currency symbols or text. Format them as numbers in the field properties and use the Number() wrapper in your JavaScript to force numerical evaluation.

Can I compare more than two fields using the Math.min method?

Yes, the Math.min() JavaScript function can accept multiple arguments. Simply retrieve the values of your additional fields and include them in the parenthesis, separated by commas, such as: Math.min(a, b, c, d, 250000).

How do I stop the fixed amount from displaying when the form is empty?

When the source fields are empty, their numeric value evaluates to 0. You can prevent the field from prematurely displaying the fixed amount or a 0 by adding a condition at the top of your script checking for blank fields: if(this.getField('A3').value == '' && this.getField('A8').value == '') { event.value = ''; } else { // calculate minimum }.