Copy link to clipboard
Copied
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?
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;
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
And what might that be?
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
Seems to work (though I have no idea why)! Thanks!