Skip to main content
Participating Frequently
May 22, 2022
Answered

negative dollar amount format

  • May 22, 2022
  • 1 reply
  • 1257 views

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?

 

This topic has been closed for replies.
Correct answer try67

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;
	}
}

1 reply

try67
Community Expert
Community Expert
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. 

Participating Frequently
May 23, 2022

And what might that be?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
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;
	}
}