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

number field formatting

Explorer ,
Oct 15, 2018 Oct 15, 2018

Copy link to clipboard

Copied

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

Views

476

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 = '';

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

The second part of that condition is not necessary.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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....

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks Thom!

 

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

It has helped me so much build nice forms. 

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

You're Welcome! Happy to help

 

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

Votes

Translate

Translate

Report

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