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

negative dollar amount format

Explorer ,
May 22, 2022 May 22, 2022

A client would like negative dollar amounts in her form to be displayed with parentheses, minus sign, and dollar sign (e.g., "(-$12.34)"), in addition to being red. How do I do that?

 

TOPICS
PDF forms
1.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
May 23, 2022 May 23, 2022

Try this code:

 

if (event.value) {
	if (Number(event.value)<0) {
		event.target.textColor = color.red;
		event.value = "(" + util.printf("%,0.2f", event.value).replace("-", "-$") + ")";
	} else {
		event.value = "$" + util.printf("%,0.2f", event.value);
		event.target.textColor = color.black;
	}
}

View solution in original post

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 ,
May 22, 2022 May 22, 2022

The built-in options that will do it will not display the minus-sign, so you'll need to write your own custom Format script to achieve it. 

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 ,
May 22, 2022 May 22, 2022

And what might that be?

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 ,
May 23, 2022 May 23, 2022

Try this code:

 

if (event.value) {
	if (Number(event.value)<0) {
		event.target.textColor = color.red;
		event.value = "(" + util.printf("%,0.2f", event.value).replace("-", "-$") + ")";
	} else {
		event.value = "$" + util.printf("%,0.2f", event.value);
		event.target.textColor = color.black;
	}
}
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 ,
May 26, 2022 May 26, 2022
LATEST

Seems to work (though I have no idea why)! Thanks!

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