How to Format Currency as French Canadian Dollars in Acrobat JavaScript
Question details
The user needs to format a PDF currency field to display numeric values in the French Canadian style (e.g., 1 234,56 $) using JavaScript, while avoiding NaN errors caused by mixed separators.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Developing interactive PDF forms that require specific regional currency formatting and robust input validation for French Canadian users.
- Observed behavior
- When users input numbers containing both decimal and thousands separators, the field produces NaN (Not a Number) errors unless the format is explicitly defined or restricted via scripting.
Ensure you have access to the 'Prepare Form' tools in your PDF editor and possess a basic understanding of adding custom JavaScript to form field properties.
Use Custom Format and Keystroke Scripts
Apply a custom JavaScript formatting script to arrange separators correctly, append the dollar sign, and use a keystroke script to prevent invalid characters like spaces.
Acrobat's built-in formatting may not natively support the exact French Canadian layout by default. By combining a formatting script to arrange the output and a keystroke script to sanitize the input, you ensure clean data collection.
Open your PDF in 'Prepare Form' mode. Right-click the target text field and select 'Properties', then navigate to the 'Format' tab.
Select 'Custom' from the format category drop-down. In the Custom Format Script box, enter: event.value = util.printf("%,2.2f $", event.value).toString().replace(/\./gim, " "); to format the output with a dollar sign.
Switch to the Custom Keystroke Script box and add code to block manual spaces: if (event.change == " ") { event.change = ""; }. This prevents users from breaking the numeric input with spacebars.

Parse Ambiguous Input Using Regular Expressions
Use JavaScript regex to split user inputs safely and extract the decimal portion before reconstructing the desired format.
Use Built-In Number Formatting as a Fallback
If custom JavaScript proves too complex, rely on Acrobat's built-in number formatting to achieve a stable numeric output.
Manage PDF Forms Easily with WPS Office
While Acrobat JavaScript provides deep customization, building and managing complex PDF forms can be daunting. WPS Office offers a highly compatible, free alternative with intuitive PDF viewing, editing, and form-filling capabilities. Enjoy seamless standard PDF compatibility and a familiar, user-friendly interface.

Frequently Asked Questions
Why does my PDF currency field show NaN?
NaN (Not a Number) occurs when the PDF engine attempts a calculation on a string it cannot parse as a valid number. This typically happens when users input unexpected formatting characters, such as multiple commas or spaces, without strict validation.
How do I stop users from typing spaces in a PDF text field?
You can block spaces by using a Custom Keystroke Script in your form field properties. Entering 'if (event.change == " ") { event.change = ""; }' will actively reject any spacebar inputs.
What does util.printf do in Acrobat JavaScript?
The util.printf method is an Acrobat-specific function used to format numbers and strings. For example, using '%,2.2f' tells the application to format the input as a floating-point number with two decimal places and thousands separators.
Can I edit PDF forms using WPS Office?
Yes, WPS Office includes a built-in PDF toolset that allows you to open, fill out, and manage standard interactive PDF forms with high compatibility and performance.




