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

number field formatting

Explorer ,
Oct 15, 2018 Oct 15, 2018

Hi,  A would like to set this kind of format in number field:  1 221,00   1 546 684,54 154,00 etc.

I know one way:

event.value = util.printf("%,2.2f",event.value).toString().replace(/\./gim," ");  BUT if number field is empty, it shows "0,00".

ButI don't want to see "0,00" in empty number fields, just nothing. Could anybody help ?  Robert

TOPICS
Acrobat SDK and JavaScript , Windows
934
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
Engaged ,
Nov 08, 2018 Nov 08, 2018

I'm just throwing this out there maybe someone else will chime in....

Would it be possible to put in an if statement??

var checkForZeros = this.getField("the field name").value;

if (checkForZeros == "0,00") {

// then hide the field

}

Just a thought

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 08, 2018 Nov 08, 2018

This is the code I use when I don't want zero to show for a blank field:

if(event.value == 0 | event.value == '') event.value = '';

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 08, 2018 Nov 08, 2018

The second part of that condition is not necessary.

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Complete code to add in the Format script

 

if(event.value == 0 | event.value == '')
{
event.value = '';
}
else
{

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

 

Thanks for the previous info....

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 06, 2019 Nov 06, 2019

The "or" symbol in your if statement is incorrect. The single bar "|" is a bitwise OR, you want a logical OR

 

if(event.value == 0 || event.value == '')

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

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
Explorer ,
Nov 06, 2019 Nov 06, 2019

Thanks Thom!

 

I am getting better thanks to your material..........on pdfscripting.com

It has helped me so much build nice forms. 

 

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 06, 2019 Nov 06, 2019
LATEST

You're Welcome! Happy to help

 

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

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