How to set own (number, specific) format?  SOLVED

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
User avatar
siSINka
User
Posts: 40
Joined: Sun Apr 07, 2019 11:55 am
Location: Czech Republic

How to set own (number, specific) format?

Post by siSINka » Tue Apr 16, 2019 9:15 am

¨I am a newbie in PDF-XChange editor.
In my form I need to set specific number format:

number with two decimal places after comma & space as thousands separator. Number, because calculation follows…

Examples:
12 345, 67
123,45
1 234 567,89
0,00

Can I add this format anywise?
I found no "space separator" there,
separator.png
separator.png (21.06 KiB) Viewed 1819 times
Second format, Czech ZIP code, format "000 00" is needed (example: 445 01). Build-in format is set to "00000", can I add this?


Thanks very much for helping me.

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13597
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to set own (number, specific) format?

Post by Tracker Supp-Stefan » Tue Apr 16, 2019 11:08 am

Hello siSINka,

Under the Format Value entries for the field, please select "Custom Action" then for "Format Action" there would be "Run a JavaScript" entry. Click the three dots next to it:
format_action.png
format_action.png (7.28 KiB) Viewed 1807 times

And then in the new window that will open - copy and paste either this:

Code: Select all

if (event.value) {
    event.value = util.printf("%,0.2f", event.value ).split(',').join(' ');
}
If you want your number to be formatted as 123 456 789.10 (decimal separator being dot)

or this:

Code: Select all

if (event.value) {
    event.value = util.printf("%,2.2f", event.value ).split('.').join(' ');
}
If you want it formatted as 123 456 789,10 (decimal separator being coma)

Regards,
Stefan

User avatar
siSINka
User
Posts: 40
Joined: Sun Apr 07, 2019 11:55 am
Location: Czech Republic

Re: How to set own (number, specific) format?

Post by siSINka » Tue Apr 16, 2019 12:01 pm

Thanks very much!

I see, that red number is "count of numbers" after decimal dot/comma.
If "0", number is in format 0 000 000, por example 1 234
if (event.value) {
event.value = util.printf("%,0.0f", event.value ).split(',').join(' ');
}
And our ZIP code?
Format: 000 00

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13597
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to set own (number, specific) format?

Post by Tracker Supp-Stefan » Tue Apr 16, 2019 12:11 pm

Hello siSINka,

Yes the .2 is the number of characters to be displayed after the decimal separator.
Attached you will find two pages extracted from this file:
https://www.adobe.com/content/dam/acom/ ... erence.pdf

Where the printf syntax is explained.

As for ZIP codes - we have the "Category: Special" type for form fields - so select that, and from there the desired ZIP code template.

Regards,
Stefan
Attachments
Pages from js_api_reference.pdf
(179.99 KiB) Downloaded 26 times

User avatar
siSINka
User
Posts: 40
Joined: Sun Apr 07, 2019 11:55 am
Location: Czech Republic

Re: How to set own (number, specific) format?

Post by siSINka » Tue Apr 16, 2019 12:30 pm

I found build-in ZIP format in editor previously, but it is as "00000", I need "000 00" with space between 3. and 4. numbers. For example "735 01".

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13597
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to set own (number, specific) format?

Post by Tracker Supp-Stefan » Tue Apr 16, 2019 1:40 pm

Hello siSINka,

I will need to check with a colleague from the dev team on how to achieve that.
Is the ZIP code digits only or can it be any alpha numeric symbols?

Regards,
Stefan

User avatar
siSINka
User
Posts: 40
Joined: Sun Apr 07, 2019 11:55 am
Location: Czech Republic

Re: How to set own (number, specific) format?

Post by siSINka » Tue Apr 16, 2019 2:09 pm

Only digist, 0-9, format 000 00.

Ivan - Tracker Software
Site Admin
Posts: 3611
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: How to set own (number, specific) format?  SOLVED

Post by Ivan - Tracker Software » Tue Apr 16, 2019 3:19 pm

One of the ways to do that would be to use the following JavaScript:

Code: Select all

// convert current field value to a number
var n = 1 * event.value;
// format it
event.value = util.printx("999 99", util.printf("%05d", n));
HTH
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

User avatar
siSINka
User
Posts: 40
Joined: Sun Apr 07, 2019 11:55 am
Location: Czech Republic

Re: How to set own (number, specific) format?

Post by siSINka » Tue Apr 16, 2019 3:35 pm

Yes! My problem is solved.
Thank you very much!

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13597
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to set own (number, specific) format?

Post by Tracker Supp-Stefan » Tue Apr 16, 2019 3:36 pm

:)

Post Reply