Skip to main content
Known Participant
January 29, 2020
Answered

Number format [# ##0,00] in number field

  • January 29, 2020
  • 3 replies
  • 5609 views

Hi,

Unfortunately in PDF there is no option to set format in number field like this in Excel '# ##0,00'

example: 1 456 123,45 or 1 456,62. 

Somebody knows the script which format number like in example above ???

PLEASE HELP !!!!

 

Wieslaw

 

This topic has been closed for replies.
Correct answer Thom Parker

Ok, so that's simple, to convert it into a number for an Acrobat calculation, just replace the "," with a "."

 

event.value = util.printf("%,2.2f",event.value.replace("\,",".")).toString().replace(/\./gim," ");

 


Here's a double RegExp that will perform the same formatting;

 

event.value = event.value.replace(/(\d+)(p=\,)?/,function(a){return a.split("").reverse().join("").replace(/(\d{3})/g,"$1 ").split("").reverse().join("");})

3 replies

JR Boulay
Community Expert
Community Expert
April 30, 2020

Et pour ne pas afficher un zéro tout seul il faut lui ajouter une autre ligne, toujours en script de "format personnalisé" :

 

event.value = util.printf("%,2.2f",event.value).toString().replace(/\./gim," ");

if (event.value == 0) {event.value = ""};

 

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
April 30, 2020

Thank you very much for your answer, but unfortunately it doesn't work

Please look: https://www.iform.pl/txtfile/example.pdf

I still have ''0,00", these fields should be empty, other thing is I need to use comma instead of dot. If I use comma, I have a result: 1,#R

 

 

JR Boulay
Community Expert
Community Expert
April 30, 2020

Le plus simple pour afficher le format Français (espace entre les milliers et virgule avant les décimales) avec 2 décimales c'est d'utiliser ce script de "format personnalisé" :

 

event.value = util.printf("%,2.2f",event.value).toString().replace(/\./gim," ");

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
January 29, 2020

You would need to write your own custom Format and Kesytroke scripts to do that.

Known Participant
January 29, 2020

OK, I know that, have you encountered such a script? 

Thom Parker
Community Expert
Community Expert
January 29, 2020

Have you looked over the existing number format presets?

 

I don't think there is one that uses a " " for the thousands separator, but you can do this with a script

Here's the Acrobat JavaScript reference entry for the function you need.

https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/#t=Acro12_MasterBook%2FJS_API_AcroJS%2Futil_methods.htm%23TOC_printfbc-4&rhtocid=_6_1_8_78_0_3

 

I believe you'll need to do this is a two step process. Format using a "." separator, then replace the "." with a " ".

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often